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.

  1. 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.

  2. 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 .profile

This 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 ~/.profile

verify

echo $PATH

If 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.

  1. 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.

  2. 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 install

verify

openssl version

if you get

OpenSSL 1.0.1e 11 Feb 2013

Good, let’s go to the next step.

4. Install Ruby 2.0 from source code

  1. Download
    Go to Ruby official site, download the package named as Ruby 2.0.0-p0

  2. 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 install

verify

ruby -v

You can get

ruby 2.0.0p0

and run

sudo gem update

You 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!