How to compile and install Ruby 2.0 on Mac without Homebrew or RVM
First of all, congratulation to Ruby community!
After 20 years, Ruby 2.0 has been released. This milestone release not only represents the popularity of Ruby, but also predicts the bright future of Ruby. Thanks, matz.
Well, today I would like to share some tips on compiling and installing Ruby 2.0 from source code on Mac, without brew or RVM. I hope this article will help you.
1. Why I write this article.
-
I don’t want to install RVM or Homebrew.
Yes I know a lot of people choose them, and they are powerful.
I just don’t want to install either. -
If you want to compile Ruby 2.0 on Mac, like me, maybe you will meet an issue with OpenSSL.
Because the built-in OpenSSL version is outdated.
So what should we do?
2. Prepare
Set the path
Launch your iTerm or Terminal.app, and type as following:
sudo open -a TextEdit .profileThis command will launch a TextEdit.app, in the new window, in the end of this file, add the following line:
export PATH="/usr/local/ssl/bin:/usr/local/bin:$PATH"Save the file, close the file.. You should reload your environment by typing the following line:
source ~/.profileverify
echo $PATHIf you see /usr/local/ssl/bin:/usr/local/bin: in the beginning, good enough, you can go to the next step.
3. Install OpenSSL from source code
The built-in OpenSSL version is OpenSSL 0.9.8r, and the current release version of OpenSSL is OpenSSL 1.0.1e.
Since Ruby 2.0 requires OpenSSL 1.0.1e or above, we need to update it manually.
Here is the instruction of installing OpenSSL from source on your Mac.
-
Download
Go to OpenSSL official site, download the package named as openssl-1.0.1e.tar.gz or newer version.
(By default, it will be saved to ~/Downloads/ folder, if you save this file to other location, modify the codes below when necessary)
When the download process finishes, double click to unpack it. You will get a folder. -
Compile and install Launch your iTerm or Terminal.app, and type as following:
cd Downloads/
cd openssl-1.0.1e/
./Configure darwin64-x86_64-cc
make
sudo make installverify
openssl versionif you get
OpenSSL 1.0.1e 11 Feb 2013Good, let’s go to the next step.
4. Install Ruby 2.0 from source code
-
Download
Go to Ruby official site, download the package named as Ruby 2.0.0-p0 -
Compile and install
cd Downloads/
cd ruby-2.0.0-p0/
./configure --with-opt-dir=/usr/local/ssl/ --with-gcc=clang --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1
make
sudo make installverify
ruby -vYou can get
ruby 2.0.0p0and run
sudo gem updateYou should not meet any error message.
That means you have successfully installed Ruby 2.0 on your Mac.
Now, enjoy programming with Ruby 2.0.0!