Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
200 lines (127 sloc) 4.34 KB

How to install Ruby locally from source

This how-to is an approach to use to solve the following problems:

  • Ruby version management tools (RVM, rbenv, etc) add complexity when full features are not required.
  • Ruby versions installed by package managers (apt-get, etc) lag behind the latest stable version.

The following steps detail an approach to use on a Debian derived distributions (Linux Mint, Ubuntu, etc).

All commands are performed from the user's home directory unless otherwise stated.

Build tools and libraries

Install the necessary tools and libraries by running the following command:

$ sudo apt-get install build-essential autoconf bison git libreadline-dev libssl-dev libyaml-dev libncurses-dev libffi-dev tk-dev libgdbm-dev

Ruby to build Ruby

Building Ruby from source requires an installed Ruby version. Install the package manager's version of Ruby:

$ sudo apt-get install ruby

Create installation directory and add to PATH

The popular approach is to install under a bin directory in the user's home directory (e.g. /home/yerv000/bin). This approach is not recommended as it does not offer seperation of space which comes very useful when switching to a different version of Ruby.

The following approach is more flexible and adds seperation of space.

Create a local directory to hold all locally installed programs (Ruby, Node, etc):

$ mkdir ~/local

Create a ruby subdirectory to hold the Ruby installation:

$ mkdir ~/local/ruby

Add the Ruby binary to the search path. Append the local Ruby path to the .profile file present in the user's home directory:

$ echo 'PATH=$HOME/local/ruby/bin:$PATH' >> ~/.profile

Log out and log back in for the changes to take effect.

Create source directory and clone Ruby repository

Create a directory to hold source codes:

mkdir ~/src

Clone the Ruby repository under the ~/src directory:

$ cd ~/src
$ git clone

Create shell script to build and install Ruby

Create a file called in the ~/src directory using the following commands:

$ cd ~/src
$ touch
$ chmod +x

Copy and paste the following content to using your preferred editor:

cd ~/src/ruby
autoconf -f
./configure --prefix=$HOME/local/ruby --enable-shared
make clean
make install
make clean

List available tags and checkout version to build

Change current directory to ~/src/ruby:

$ cd ~/src/ruby

List available tags:

$ git tag

Tags are version numbers and patch levels. Pick a tag and check it out. Let us pick Ruby 2.0.0p195:

$ git checkout v2_0_0_195

Git should state that it is in detached head and list the tag name.

Run build script

Change current directory to ~/src:

$ cd ~/src

Run build script:

$ ./

Verify Ruby installation

Run the following command:

$ which ruby

Output should point to ~/local/ruby/bin/ruby.

Verify installed Ruby version:

$ ruby --version

Output should correspond to the tag version picked, in our example:

ruby 2.0.0p195 (2013-05-14 revision 40731) [x86_64-linux]

Deleting Ruby installation

To completely delete the locally installed Ruby version execute the following:

$ rm -rf ~/local/ruby/*

Now you are able to checkout a different version and do a clean install.

Maintaining different Ruby versions

Simply rename the ~/local/ruby directory:

$ mv ~/local/ruby ~/local/ruby_2_0_0_195

Recreate an empty local Ruby directory:

$ mkdir ~/local/ruby

Now you are ready to checkout a specific tag (e.g. v1_9_3_392) in the ~/src/ruby directory and rerun the build script.

To return to the 2.0.0p195 version without deleting the just installed 1.9.3p392 version:

$ mv ~/local/ruby ~/local/ruby1_9_3_392
$ mv ~/local/ruby2_0_0_195 ~/local/ruby

Note about gems

Use Bundler to manage gems. All gems will be under the ~/local/ruby directory, so when you rename the directory to switch to a different Ruby version the gems move with the Ruby binaries.

Keeping Ruby repository up-to-date

To pull the latest changes run the following:

$ cd ~/src/ruby
$ git checkout trunk
$ git pull
$ git pull --tags