Installing Ruby on Ubuntu

First, update apt-get:

sudo apt-get update

Install the rbenv and Ruby dependencies with apt-get:

sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

Now we are ready to install rbenv. The easiest way to do that is to run these commands, as the user that will be using Ruby:

  • cd
  • git clone git://github.com/sstephenson/rbenv.git .rbenv
  • echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”’ >> ~/.bash_profile
  • echo ‘eval “$(rbenv init -)”’ >> ~/.bash_profile
  • git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
  • echo ‘export PATH=”$HOME/.rbenv/plugins/ruby-build/bin:$PATH”’ >> ~/.bash_profile
  • source ~/.bash_profile

Note: On Ubuntu Desktop, replace all occurrences .bash_profile in the above code block with .bashrc.

This installs rbenv into your home directory, and sets the appropriate environment variables that will allow rbenv to the active version of Ruby.

Now we’re ready to install Ruby.

Install Ruby

Before using rbenv, determine which version of Ruby that you want to install. We will install the latest version, at the time of this writing, Ruby 2.2.3. You can look up the latest version of Ruby by going to the Ruby Downloads page.

As the user that will be using Ruby, install it with these commands:

rbenv install -v 2.2.3
rbenv global 2.2.3

The global sub-command sets the default version of Ruby that all of your shells will use. If you want to install and use a different version, simply run the rbenv commands with a different version number.

Verify that Ruby was installed properly with this command

ruby -v

It is likely that you will not want Rubygems to generate local documentation for each gem that you install, as this process can be lengthy. To disable this, run this command:

echo "gem: --no-document" > ~/.gemrc

You will also want to install the bundler gem, to manage your application dependencies:

gem install bundler