Whether you are using ubuntu 10.04 or 9.10, the ruby on rails installation should be the same. So in order to install ruby on rails in ubuntu, you need to have ruby ready first.
There are two choices for you to install ruby, either install ruby from repository or from source. To install ruby from repository, open terminal and type the following command:
$ sudo apt-get install ruby-full build-essential
In order to build ruby from source, you need to have the following pre-requisite packages:
$ sudo apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev
Now you need to download ruby source with the following command:(note you may choose to install different ruby version with different download urls. Refer to the Source Code section of the ruby download page)
$ wget ftp://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz
Unzip the files:
tar xzf stable-snapshot.tar.gz
Compile and install ruby:
$ cd ruby/ $ ./configure $ make $ sudo make install
Now run ‘irb’, if you didn’t see any errors, congratulations, you have successfully installed ruby.
Before you install rails, you should have gem ready. Gem is a packaged Ruby application or library. You can use gem to install a lot of free and helpful packages including ‘rails’ framework. You may want to refer to the gem doc if you are interested.
Install gem with the following command:
$ wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.2.tgz $ tar xzvf rubygems-1.3.2.tgz $ cd rubygems-1.3.2 $ sudo ruby setup.rb $ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
Now with gem you can start installing rails:
$ sudo gem install rails
Do note that this will install the latest version of rails (2.3.5). If you intend to install the previous versions, use the following command:
$ sudo gem install --version = 2.2.2 rails
By default, ruby on rails support sqlite3 under development environment. However, in order to use that, you need to install sqlite and sqlite-ruby gem first.
$ sudo apt-get install sqlite3
Now, type sqlite3 command in terminal. If you didn’t see any error and is in the sqlite3 mode, you have successfully installed sqlite3. Type ‘.quit’ to exit.
Now it is time to install sqlite3-ruby gem. Try typing the following command in the terminal:
$ sudo gem install sqlite3-ruby
You should be able to see the following errors in your screen:
Building native extensions. This could take a while…
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb install sqlite3-ruby
checking for fdatasync() in -lrt… yes
checking for sqlite3.h… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
This is quite annoying. However, no worries, nothing cannot be solved in this world. In order to install sqlite3 for ruby on rails. You need to have libsqlite3-dev package installed. Try the following command:
$ sudo apt-get install libsqlite3-dev $ sudo gem install sqlite3-ruby
Now you may see a bunch of messages like the following. That’s normal. Don’t bother about that.
No definition for _wrap_sqlite3_result_text16
No definition for _wrap_sqlite3_result_text16le
No definition for _wrap_sqlite3_result_text16be
No definition for _wrap_sqlite3_result_value
No definition for _wrap_sqlite3_aggregate_context
Now you are ready to use your ruby on rails in ubuntu. Have fun with ruby on rails.