How to Install Ruby on Rails 4 in Linux

Pubudu Kodikara
Leafy Code Blog
Published in
3 min readDec 6, 2015

Yesterday we talked about the advantages of using Ruby on Rails. After reading it, some of you might want to get started right away. So, today we are going to see how to install the latest version of Rails on a Linux machine. We will show you how to do it in Ubuntu. For others its mostly the same way (simply change the package manager). Now we are going to use RVM to manage Ruby. With RVM you can easily manage several versions of Ruby on your machine.

  • First of all, open the Terminal and go to Edit > Profile Preferences and select the tab Title and Command
  • In there tick Run command as a login shell and Close
  • Now we need the latest packages of Git (if you haven’t used it you better try it now) and Nodejs. The versions in the Ubuntu repository is outdated.

So, lets add some ppas :

sudo add-apt-repository ppa:git-core/ppa
sudo apt-add-repository ppa:chris-lea/node.js sudo apt-get update
  • Next we need to install Git, Nodejs (required for Rails development) and some other dependencies…

with these commands :

sudo apt-get install git nodejs build-essential curl libxslt-dev libxml2-dev libsqlite3-dev
  • When you install Rails its going to install a lot of documentation files for each gem. You might not want this to happen!

So let ask it not to do that by creating a .gemrc file in your home directory…

gedit ~/.gemrc

and adding the following lines to that file…

install: --no-rdoc --no-ri update: --no-rdoc --no-ri
  • You can easily download Ruby from the package manager. But that Ruby version is outdated. We will install the latest version of Ruby using RVM.

First, lets install RVM (Run them as a normal user account. Not root.) :

curl -sSL https://get.rvm.io | bash -s stable
  • Now close and open your Terminal to load the rvm source.

After that install the RVM requirements :

rvm requirements
  • Next lets install Ruby! First get the latest ruby version number from here : https://www.ruby-lang.org/en/downloads/ . Then use that to install ruby. At the time of writing, the latest Ruby version is 2.1.2.

So here’s how I will install it :

rvm install 2.1.2

Finally lets install Rails :

gem install rails

Lets create your first app :

rails new test_app
  • This will create your application with all the basic requirements. Next we will install the default plugins ( gems ) and…

Run the development server to test it :

cd test_app bundle install rails server

Note : You can use rails s instead of rails server

If you can see something like the above screen shot, you have successfully installed Ruby on Rails! Congratulations!

Next steps… Learn Ruby on Rails :

You might think you first need to learn Ruby before learning Rails. No that’s not true. You can first learn Rails if you want. Here are some great tutorials for you to start :

--

--

Pubudu Kodikara
Leafy Code Blog

Im a Blogger, Web Developer, Designer, and an inventor :)