This guide is valid for the following distributions:
While there is a nice tutorial in the Ruby on Rails wiki, it’s by no means complete. According to it, you should only type: apt-get install rails
to have the newest Rails installed on Ubuntu. It installs both Ruby and Rails, but what about rubygems? Sorry, not this time. There is also another caveat. Although commands like rails test
and ruby script/server
are working properly, ruby/console
is not. If you had the misfortune of experiencing the aforementioned behavior, then this tutorial is just for you.
Pre requirements:
nano /etc/apt/sources.list
Add the following at the end of the file (replace edgy with breezy if you are running Breezy, dapper for Dapper, etc.):
# All Ubuntu repositories
deb http://archive.ubuntu.com/ubuntu edgy main restricted universe multiverse
Update your apt sources:
apt-get update
Installation:
Install Ruby with developer’s libraries:
apt-get install ruby ri rdoc irb ri1.8 ruby1.8-dev libzlib-ruby zlib1g
Download and install Ruby Gems (no .deb package, unfortunately):
wget http://rubyforge.org/frs/download.php/17190/rubygems-0.9.2.tgz
tar xfvz rubygems-0.9.2.tgz
cd rubygems-0.9.2
ruby setup.rb
Update your RubyGems (also updates the gems cache):
gem update --system
If you get Could not find rubygems-update (> 0) in the repository
or a similar error, you need to delete your RubyGems cache:
$ gem env gemdir
PATH_TO_DEFAULT_GEM_REPOSITORY
$ rm PATH_TO_DEFAULT_GEM_REPOSITORY/souce_cache
and
rm $HOME/.gem/source_cache
In the next step install the OpenSSL bindings for Ruby (needed to install signed gems). They are required if you get the following error: SSL is not installed on this system, while installing signed gems like rake
:
apt-get install libopenssl-ruby
And the last one:
gem install rails -y
And this is basically it. There are, however, depending on your needs, some…
Additional steps:
One of them is setting up the Rails to connect to the MySQL database in a proper way. We will be using the MySQL C bindings, which, for one, support the MySQL old style passwords (which is set as default for Ubuntu 5.04), but are also significantly faster (in the 2-3x range) than the native Ruby MySQL bindings. First, we will need to install the gcc
compiler (and libc6-dev
if you don’t have it already installed). Although strange it may seem, as a default it is not installed on a clean Ubuntu installation.
apt-get install gcc libc6-dev
MySQL development libraries are also required (mysql_config plus mysql/include):
apt-get install libmysqlclient14-dev
(for MySQL 5.0 you might be better of with libmysqlclient15-dev
).
And now we can install C MySQL bindings:
gem install mysql
If you get "sh: make: not found"
do:
apt-get install make
or if you have it already installed, add it to your path:
export PATH=/usr/bin:"${PATH}"
And, of course, in the end install Mongrel:
gem install mongrel -y
And that’s it. Rails installation is complete. Complicated? Not really :) Happy coding!