Installing Ruby/Rails on ubuntu is not hard, but some little obstacles might be confusing.
This guide has been tested on ubuntu 10.04 “Lucid Lynx”, ubuntu 10.10 “Maverick Meerkat” and ubuntu 11.04 “Natty Narwhal”, but should also work for other debian based linux distors.
The debian dilemma
Unfortunately, on debian and ubuntu, the whole Ruby installation is split into different packages. When installing the
ruby package, some parts of Ruby are not installed, for example
Although there is a way to install all Ruby packages with the command
sudo apt-get install ruby-full, I would not recommend it. Besides getting some emacs packages (?), one (at least me) quickly loses the overview about which packages are installed and which are not..
The recommended way to install Ruby is using the Ruby Version Manager (RVM). If you do not want to depend on external scripts you must choose one of these two ways: Either using the ubuntu repositories, or building Ruby from source. You should try to not mix these approaches!
Option 0: Use Ruby Version Manager
Use this option, if there is no reason, why you should use one of the other ways ;)
RVM makes it easy to install multiple rubies and switch between them.
sudo apt-get install curl git-core bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Add this to your
~/.bashrc (this step is not needed in newer versions of rvm):
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Then restart your terminal or enter:
Now, Ruby can be installed with:
sudo apt-get install libruby1.8 libruby1.9 zlib1g-dev libssl-dev libreadline-dev build-essential rvm install ruby-1.9.3 rvm use ruby-1.9.3 --default
Please note: Do not use
sudo for installing gems!
Information about how to install different versions can be found by entering
Ruby is ready now :). More information about rvm+bundler can be found in this blog article
Option 1: Install Ruby 1.8 from the ubuntu repositories
This way is recommended, if you just want to have a working version of Ruby and do not care about the details.
The disadvantage (or advantage?) of this approach is that you depend on the ubuntu package maintainers. They decide, when to upgrade. They decide, what name schema and directory structure is used.
Anyway, first of all, you should add the
ubuntu-on-rails ppa repository, sometimes they have newer versions of some Ruby components. Do it by typing:
sudo add-apt-repository ppa:ubuntu-on-rails sudo apt-get update
Now get the essential ruby packages:
sudo apt-get install ruby rubygems irb ri rdoc rake
The dependencies should look like:
irb1.8 libreadline-ruby1.8 libreadline5 libruby1.8 rdoc1.8 ri1.8 ruby1.8 rubygems1.8
But you need more packages!
sudo apt-get install build-essential ruby1.8-dev libopenssl-ruby
These extra packages are very important – odds are high that you will need them. Unfortunately they are not in the standard package dependencies, partly because of some licensing issues – readline and openssl have incompatible licenses.
After getting all packages, there is another little step necessary: You have to add the
gem path to your global
PATH, so that executables new gems can be easily called from the command line. Do it by adding the following line to your
Then restart your terminal or enter
Ruby is ready now :)
A little side note: Because of a safety restriction of ubuntu,
sudo does not work with executables of gems. Usually you don’t need
sudo these, but exceptions might occur. To enable it, add the gem bin path to the the global
/etc/bash.bashrc and apply this workaround.
Option 2: Build it from source
This way is recommended, when you want to have full control over your installation.
Do not get deterred, it is not that hard. Firstly, get the needed dev packages:
sudo apt-get install libruby1.8 libruby1.9 zlib1g-dev libssl-dev libreadline-dev build-essential
tar -xzf ruby-1.9.3-p0.tar.gz
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p334.tar.gz wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.5.tgz tar -xzf ruby-1.8.7-p334.tar.gz tar -xzf rubygems-1.8.5.tgz
Now navigate to the extracted ruby directory and run:
./configure make sudo make install
To install both versions at the same time (without RVM), you can pass a
--program-suffix option to one of the
./configure commands before compiling.
You can check if this was successful with:
Optional: Install the ruby documentation (used by
sudo make install-doc
In 1.9, you should also update rubygems:
sudo gem update --system
For 1.8, change to the extracted
rubygems-1.6.2 directory and run:
sudo ruby setup.rb
Ruby is ready now :).
Install your gems
You should rarely (never) install gems from the ubuntu repositories (apt-get), but those from the gem repository. However, sometimes you need some additional library packages. If the installation of a gem fails, you often just need to install the right
XXXX-dev package, and it suddenly works. To find out which one, use the ubuntu package search or your search engine.
Choose a database, for example sqlite3
sudo apt-get install sqlite3 libsqlite3-dev sudo gem install sqlite3-ruby
sudo apt-get install mysql-server libmysqlclient-dev sudo gem install mysql
and install the framework:
sudo gem install rails