Rails 3/Installing Ruby and Rails
In this section we will see how to install Ruby on Rails on Ubuntu GNU Linux distro. At the point of writing this piece of text we have Ubuntu 10.10. We will see how to install Rails 3.x.x in it.
The first step is to launch your terminal by going to Applications -> Accessories -> Terminal.
First, we will install tools that will compile Ruby source code; to do so in your terminal type the following:
$ sudo apt-get install gcc g++ build-essential libssl-dev libreadline5-dev zlib1g-dev linux-headers-generic libsqlite3-dev
Next, we will download the Ruby source code using wget; to do so type the following in terminal:
$ wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
The above command will download Ruby 1.9.2 source code. The downloaded file is in tar.gz format, it must be unzipped; to do so type the following:
$ tar -xvzf ruby-1.9.2-p0.tar.gz
Next, we will compile and install Ruby using the following commands (type the commands one by one):
$ cd ruby-1.9.2-p0/
$ ./configure --prefix=/usr/local/ruby
$ make && sudo make install
Next, we need to tell our operating system that Ruby is installed in /usr/bun/ruby ; to do so we need to add the path to /etc/environments file. To do so, type the following
$ sudo gedit /etc/environment
The file opens and you might see something like this:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
To the path string add :/usr/local/ruby/bin , it must at last look something like this:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
Now, we run the source command for the file /etc/environment to apply changes.
$ source /etc/environment
Now check if everything is OK by typing the following:
$ ruby -v
If everything is done correctly, the output will look something like this:
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
Now we will create symbolic link to ruby and gem using the following commands:
$ sudo ln -s /usr/local/ruby/bin/ruby /usr/local/bin/ruby
$ sudo ln -s /usr/local/ruby/bin/gem /usr/bin/gem
Now we will install rails with gem using the following commands (type them one by one in terminal):
$ sudo gem install tzinfo builder memcache-client rack rack-test erubis mail text-format bundler thor i18n sqlite3-ruby
$ sudo gem install rack-mount --version=0.4.0
$ sudo gem install rails
To check type rails -v, you must get output like something shown below:
$ rails -v
Rails 3.0.3
When I installed Rails 3.0.3 was the stable version of Rails hence it got installed. Having installed our Rails web framework successfully lets create our first web application.