Ubuntu 12.04 LTS (Long Term Support) – Precise Pangolin has already released, and you might have upgraded from 11.10 or installed Ubuntu 12.04 LTS. In this post you will learn how to setup Ruby on Rails on a newly installed Ubuntu 12.04 LTS.

Ruby on Rails is a very popular web development framework, it is based on the principle of  “Convention over Configuration”. Although, application development using Rails is quite easy and fun but setting up rails development environment may be difficult and frustrating, specifically for beginners. I had already written a post about setting up rails on Ubuntu 11.10  but few things has changed and need to be updated for the new version of Rails, Ruby and Ubuntu.

“Hassle Free” Rails Installer for Ubuntu 12.04

Although I’ve explained the installation steps in detail but if already know how these things work then better save time by running the script – that will install Ruby on Rails on Ubuntu 12.04 along with the dependencies and RVM.

Download the Rails Installer Script (From Github)

First change some settings in Gnome Terminal. Go to Edit -> Profile Preferences -> Title and Command and check the “Run Command as login shell”  box.

Login Shell - Terminal

Then make the script executable and execute it (you may have to enter the login password once) –

sudo chmod +x rails-installer.sh
./rails-installer.sh

If anything goes wrong then let me know through comments.

Step by Step Instruction for Setting Up Rails on Ubuntu 12.04 LTS

Just follow these simple steps and withing a couple of minutes you would be creating some nice applications (and of course using Rails).

step 1.  Install git and cURL

First of all, update your package repository.

sudo apt-get update

git is a simple, fast and efficient version control system. It is easy to learn, so even if you don’t have any experience with git you can try it in your next rails project (or any other project). you will love it.

sudo apt-get install git

Curl is a simple command line utility for getting file over web protocols, based on libcurl. To install curl simply execute –

sudo apt-get install curl

step 2. Install RVM and Dependencies

RVM is not strictly required but it makes ruby management a lot easier. You can try different implementations of ruby, different versions of ruby and all without any pain. So it’s strongly recommended. but RVM requires the command to be executed as login shell, so open a terminal and go to Edit -> Profile Preferences -> Title and Command and check the box that says “Run Command as a login shell“. (look at the above snapshot)

curl -L get.rvm.io | bash -s stable

Now, you must load the RVM

source ~/.rvm/scripts/rvm

Then install additional dependencies specified by the RVM –

rvm requirements

sudo apt-get -y 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

Installing Javascript Runtime
In newer version of Rails, you also need a Javascript runtime. Although you could install it from the package repository but it’s very outdated. So I recommend installing it using the PPA. (and I’ll also update the script)

sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

step 3. Install Ruby

Now, you got RVM running, installing and running multiple versions or just one version of Ruby is very simple. To install Ruby just pass the version number to rvm install command (or some other implementation of ruby if you want; RVM also supports rbx, ree, JRuby, IRonRuby other than the default MRI) –

rvm install 1.9.3

Then select the Ruby version you want to use, (or make it default so that you don’t have to select it again in new session)

rvm use 1.9.3 --default

Now, you can check the version of ruby, you’re running right now-

ruby -v

step 4. Install Rails

RVM installs ruby as well as the gem utility (managing ruby libraries). To install rails, simply install it using the gem. It will automatically install the latest version unless you specify the version explicitly.

gem install rails

Now You’re ready to go.

rails new app_name
cd app_name
rails server

Now, open a browser and go to http://localhost:3000. 🙂

Voila 🙂

You should also check out this Ruby on Rails Interactive Video Course on Treehouse.

Note : When your Rails Application is ready, you may want to deploy it to a real server, I recommend Digital Ocean (@$5/mo, you get 512 MB RAM, 20 GB SSD and 1TB Bandwidth, cool, isn’t it.) for that, also checkout the Digital Ocean review if you want to know more about them. If you need any help then read this article about Deploying Rails Application to VPS.

Update 1 : Added a video as a reference for Rails Installer Script.

Update 2 : checkout my new rails application: Railyo – Rails freelancing jobs for cool developers!

Join the Conversation

71 Comments

  1. I love you so much!!!
    For Step 4 I would provide an example of how to specify which version of Rails one would like to install.

    Thank you

  2. i run the “rails server” command but the terminal keep showing “rails new app” usage help. I use the script to install, and everything run smoothly.

    1.  ah my mistake, have to CD to the app directory. thanks for the wonderful script

  3. Even after running the script, rails hasn’t been installed. Any clue as to why that could happen?

  4. Awesome! Thanks for explaining each command like you did, helps newcomers like myself out a lot!
    Next maybe a tutorial on getting Aptana working on linux would be nice

    1. Cool :D, although Aptana is a geat IDE for rails but a text editor like gedit or kate (VIM or Emacs for long term productivity boost) would be fine.
      gedit plugins for rails developer – http://blog.sudobits.com/2012/03/11/gedit-plugins-for-ruby-on-rails/
      Install Aptana using Eclipse – http://blog.sudobits.com/2012/04/26/how-to-install-eclipse-ide-on-ubuntu-12-04/

  5. great installer, i advise using it in root mode (sudo -s) i had some problems before i used it

  6. Very useful, thanks! One thing was different.. instead of:
    source ~/.rvm/scripts/rvmI had to do do:source /usr/local/rvm/scripts/rvm

    Perhaps because I was executing this as root..?

  7. root@fitz:/home/fitz# rvm install 1.9.3
    Already installed ruby-1.9.3-p194.
    To reinstall use:

        rvm reinstall 1.9.3

    root@fitz:/home/fitz# rvm use 1.9.3 –default
    Using /usr/local/rvm/gems/ruby-1.9.3-p194
    root@fitz:/home/fitz# ruby -v
    ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]

    Any reason why ruby -v shows it is using older version?   How do I get the system to use /usr/local/rvm/gems/ruby-1.9.3-p194?

    Thanks in advance for help – Ubuntu 12.04

    1. You might have installed ruby from the system package – e.g using the command sudo apt-get install ruby or something like that, which has a higher preference than the ruby installed via RVM. So you just need to uninstall the system ruby.

      sudo apt-get remove ruby ruby1.8

  8. Thank you for your script.
    I used vmbuilder to create a vm guest running ruby. I used your script, but i don’t have gem. How to install it ?

  9. Excellent tutorial but for the last version of nodejs use sudo add-apt-repository ppa:chris-lea/node.js 

  10. Help me please! After reboot when i try to run rails, i see an error:
    “The program ‘rails’ is currently not installed.  You can install it by typing:
    sudo apt-get install rails”

    why?

    1.  same problem here… waiting for a reply, as soon as i completed the install it was working in the terminal i did the install in, but in another terminal it was not finding rails… help please.

    2. Did you go into your terminal’s preferences, and select “Run command as login shell” BEFORE going through the installation process?

      I had the same problem when first starting out with rails.
      Check the top of the page, he has an example on how to set up your terminal

    3. Looks like rails did not get installed even for me.I have just installed on my own
      sudo apt-get install rails
      and it gets latest version of rails. After that it seems to work fine.
      Used script/server to start server.
      I am a newbie so excuse my ignorance.

  11. When I try the last command to see if Rails is working I get the following error. Any suggestions?

    /home/gwonders/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:247:in `mkdir’: Permission denied – /app_name (Errno::EACCES)

    1. Are you trying to mkdir in “/home/gwonders/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:247” ?

      If so, that prolly won’t work out so well. When you run the command “rails new your_new_app_name”, rails will generate a folder/dir in your current location. 
      For example:
          cd Desktop
          rails new test_app
      will generate a folder/dir in the Desktop directory named test_app. In it will be the contents of the test_app generated by rails.

      rails is made to be simple as far as setup and use, so don’t go overkill with it and you’ll be good

  12. I’m getting this

     ric@Iam:~$ curl -L get.rvm.io | bash -s stable
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0   185    0     0    0     0      0      0 –:–:–  0:00:19 –:–:–     0
    100  9439  100  9439    0     0    228      0  0:00:41  0:00:41 –:–:–  3030
    bash: line 365: /usr/share/ruby-rvm/RELEASE: Permission denied

    Same if I use sudo -s

    Thanks! I’m almost there.

Leave a comment

Your email address will not be published. Required fields are marked *