Source Code Installation

Download latest source tarball, and untar it:

tar xfz stable-snapshot.tar.gz

Get OpenSSL Development Libraries

You will most likely want to add openssl support. You can choose to statically compile in all dependencies, but this means you have to be sure to re-build your rubies if openssl security vulnerabilities are found (like Heartbleed).

yum -y install openssl-devel

Configure Compile Options

Now we'll enter the directory of the stable-snapshot.tar.gz, configure and install it. When configuring, we'll add an option for SSL (if you skipped that part, you can omit this flag). By default it's installed to /usr/local/, we'll change that and install to /opt/ruby/rbYYYYmmddHHMM. I like to timestamp my builds so I know when they're from. You can create an RPM for this, or recursively copy or rsync it to another folder specific to an app (rails site for example), and then create an RPM specific to that environment. Here, we'll just use the datestamp.

cd stable-snapshot;
./configure --with-openssl-dir=/usr/lib64/openssl --prefix=/opt/ruby/rb`date +%Y%m%d%H%M`

Compile and Install Ruby

Now to compile, we simply run make and pay attention to the output.

make && make install

Test New Ruby

Say this was built with timestamp 201412071746, your freshly-compiled ruby is installed to /opt/ruby/rb201412071746/.

/opt/ruby/rb201412071746/bin/ruby --version

Set Path for New Ruby

We can set this ruby bin directory in our environment's PATH to avoid typing the entire path. By placing it first, the commands (ruby, gem, etc.) will match here first before finding the system's RUBY in /usr/bin.

export PATH=/opt/ruby/rb201412071746/bin:$PATH

Check that we see the correct PATH now.

which ruby

You should see output like this