How to install Ruby on Rails in Ubuntu 11.10

Ubuntu (The latest stable version : 11.10(Oneiric Ocelot), released few weeks ago) is one of the most Linux based popular operating system and gradually becoming more popular among programmers and web developers. C/C++/Java programmers and web developers are rocking with the Ubuntu as it has a bunch of open source development tools available to increase the productivity at minimum or zero cost.

Ruby on Rails is one of the most popular framework for developing web applications using Agile approach. Rails (Latest version : 3.1) is based MVC (Model View Framework). Getting started with Rails has been little messy (On Linux platform) for beginners due to its installation/setup errors, probably due to some missing dependencies (e.g gems).Relax, it’s very simple, you just need to understand few basic things. This post has been written for those who want to get started with ‘Ruby On Rails'(commonly called as ROR) on Ubuntu 11.10 or the rails developers who want to develop cool application with Ubuntu 11.10.

To install ruby on rails in Ubuntu 11.10 (or other similar Linux distribution such as Linux Mint, Debian etc), just follow these simple steps. Although RVM is not strictly necessary but it’s strongly recommended – it will allow you to use multiple versions of Ruby, which may be be required in some cases.

step 1. Install dependencies

Install git : Git is the most popular (as well as fast and efficient; Linux kernel uses it; developed by Linux Torwalds, the same guy who developed Linux kernel) open source version control system. You can install it in one simple command to install it from the official package repository –

sudo apt-get install git

[You could also install git from the source (Download the source code, extract it and execute make && sudo make install) ]

Install Curl : Curl is a command line tool to get a file from FTP/HTTP/HTTPS server. To install, open terminal and execute the command –

sudo apt-get install curl

step 2. Install RVM (Ruby Version Manager)

Open terminal and execute the command (I assume you’ve already completed the step 1, otherwise first do that) –

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

Now, you might have to edit the bashrc file to load RVM in shell session. To do that type –

gedit ~/.bashrc

and add the following line to the end (and save the file)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Then reload the shell session using the command –

source ~/.bashrc

Now you can test whether the RVM has been installed successfully or not. Open terminal and execute the command –

type rvm | head -1

After executing above command you should be getting this output –
rvm is a function
That’s All.. You’ve successfully installed the RVM. Next, you are supposed to install few additional dependencies. To find out those programs type –

rvm requirements

After executing the above command, install the additional packages recommended by RVM –
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

step 3. Install Ruby

Now, it’s time to install the ruby version you want (you’re recommended to use either 1.8.7 or 1.9.2). The generic syntax is rvm use version_name. It will also install the associated packages such as RubyGems and Bundler.

rvm install 1.9.2

Then select the version, you want to use –

rvm use 1.9.2

If you aren’t sure about the ruby version currently being used, then type –

ruby -v

step 4. install Rails

Finally, you can install the rails gem using a simple command –

gem install rails

That’s All.
Now, create a sample application (just for testing) using Ruby on Rails.

rails new my_app
cd my_app
bundle install
rails server

Then open your browser and type the following address (to see the application running) –
http://localhost:3000

Learning Rails ?

Check out this interactive video course on Ruby on Rails at Treehouse.

Recommended Books/Tutorials for Beginners

Update 1. Fixed some typo in commands! and adds a link in resources!

Update 2. My Rails Application : Railyo – a private job board for rails developers/freelancers.

  • irina

    thanks for the tut, simple enough to follow! one issue i seem to be having is localhost:3000 does not get recognized as anything, neither in chrome nor firefox? anything that needs to be restarted?

    • W Vogl

      is your server running? what output do you see after typing [rails s] in your command line?

  • antonsash

    Thank you for your blog! =) It’s help me a lot of)

  • http://twitter.com/david_k_roberts David K Roberts

    I am trying to install rails on a clean 11.10 client… I get to the bundle install part and I can’t proceed because of sqlite3 … I try running “gem install sqlite3 -v ‘1.3.4’” and get:

    ERROR:  Error installing sqlite3: ERROR: Failed to build gem native extension./usr/bin/ruby1.9.1 extconf.rb:29:in `require’: no such file to load — mkmf (LoadError)

    I have apt-get(ted) build-essential sqlite3 libsqlite2-dev beforehand (fyi) like all other docs have expressed… I am at a complete standstill because of this… any ideas?

    • Anonymous

      try to install libsqlite3-0 package with apt-get

      • Mike

        Yes, this needs to be added to the installation instructions, otherwise you get an error stating that the header files are not installed.

        • Renju raj

          If you still get that error please try to install libsqlite3-dev
          `sudo apt-get install libsqlite3-dev`

  • Undersound

    Thanks for the very detailed instructions. Everything works except when I restart and enter try to run ruby. It says: The program ‘ruby’ can be found in the following packages:. I’m trying to install refinerycms here and that works fine following your instructions but when restarting and trying to rails server it’s not working. It’s a path issue obviously but running locate rails | grep bin only outputs stuff in the ~/.rvm folder

    • Ian Rock

      Try this at the command line:
      rvm –default 1.9.2

      • Thecaptainmurdock

        Thanks! I had the same problem as OP and this resolved it successfully.

  • Anonymous

    I found that this type of installation is not good for me. It’s just a marginal problem for specific type of libraries. Specifically my problems comes with asset management libraries written in php (assetic), that rely on ruby gems (like compass) to publish assets. The rvm single user installation do not work well for some reason…and I wasn’t able to install it system-wide. In the end I found that compiling from ruby sources was the best solution. It’s easy and it’s system-wide by definition. For anyone else rvm is the right choice.

  • Pete

    Thanks for sharing. It’s a great step-by-step manual.

    I have to run this command to install JS runtime to make it work:
    sudo apt-get install nodejs

    • Rookie on Rails

      I ran into the same problem, execjs / rubyracer was recommended but i choose nodejs too because I hear it mentioned often and that it is rather powerful. 

    • Eleazar

      Thank you, you saved me a lot of frustrating hours

  • Baskin Tapkan

    Best working instructions I have seen. Totally seamless. Thanks!

  • Matcsimpson

    You helped me out sooooo much I have been looking for a good guide/tutorial for almost a week thannnnnnk you <3

  • Dinhquangrim

    thanks, nice instructions.

  • Cjd5543

    I had to make 2 tweeks. When I ran “type rvm | head -1”, Ubuntu told me “rvm is not installed.  It suggested I install “sudo apt-get install ruby-rvm”.  I did then edited the bashrc file to point to “/usr/bin/rvm” and completed the walk through.  Worked great from that point.

  • sagiv

    one little fix: 
    at the last part – you need first to do “cd my_app” then “bundle install”

  • Goonzie

    Thanks for the great guide.

  • Amit Yadav

    Great guide

  • Alanb

    I am using your instructions using Ubuntu 11.04
    I have got to step 4 ( install Rails ) and am getting:
        ERROR:  While executing gem … (Gem::DependencyError)
        Unable to resolve dependencies: rails requires activesupport (= 3.1.3), actionpack (= 3.1.3), activerecord (= 3.1.3), activeresource (= 3.1.3), actionmailer (= 3.1.3), railties (= 3.1.3)

    What can I do to resolve this?

    • Alanb

      Did sudo apt-get install rails (instead of gem install rails) and all worked fine, no idea why
      Thanks for the post

  • http://twitter.com/A_Velouxiotis Παναγιώτης Πετρίδης

    thanks! In command ruby -v I take: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
    in command gem install rails I take: /usr/local/lib/site_ruby/1.8/rubygems.rb:29:in `require’: no such file to load — rbconfig (LoadError)

  • Nikolaos

    Great tutorial! thanks!

  • Kevin Rosenjack

    If you are using a network with a web filter / proxy RVM may indicate uninstalled even though the command appeared to work – ie. no error message.  You should actually see installation occuring after the initial install command not just a return to the command prompt.  If you don’t try putting the URL right into your browser to ensure it is not being blocked – mine was so I switched networks and all is good.

  • Luke McCarthy

    This is the first RoR install walkthrough that has worked for me, thanks 😀

  • maria jose

    gracias por la publicación… 😉

  • Pangur

    Delighted with this tutorial.  Had to change the permissions on location of gem files.  Sometimes needed to use sudo.  Otherwise, worked like a dream. Thanks very much!