A Couple of months back I had a situation, which concerned about installing Ruby on Rails and rails on my system. After reading through many blogs and posts related with installation, at last I found RVM (Ruby Version Manager) as the best option among all which is a neater way of installing Ruby on Rails. Most importantly I didn’t need to Google all the errors, which pops up while installing them using other methods. With RVM, comes lots of flexibility and installation is pretty easier.
These installation steps have been tested on ubuntu versions.
Do’s and Dont’s
- This beginner’s guide will set up a Rails Development Environment with Ruby 1.9.3, RVM and Rails 3.1.3 and is specifically written for a development environment on Ubuntu 10.10, but will probably work on many other operating systems, including older / newer versions of Ubuntu and Debian.
- If one is looking for a way to set this up on a production server then the use of the “railsready script” is recommended which installs all the necessary packages for Ruby 1.9.3p0 and then that version of Ruby itself, Bundler and Rails. Then it is left to user to install Apache or nginx to get your application online.
- Under no circumstance should one install Ruby, Rubygems or any Ruby-related packages from apt-get. This system is out-dated and leadsto major headaches. Avoid it for Ruby-related packages.
- First of all update the system,so that all the latest resources are updated to install latest packages.
- Open terminal(alt+ctrl+t).
- In terminal type:- sudo apt-get update
- Next, we’re going to install Git (a version control system) and curl which are both required to install and use RVM, and build-essential which is required to compile Ruby versions, amongst other compilable things. To install these three packages we use this command:
- sudo apt-get install build-essential git-core curl
- Installing RVM(Ruby Version Manager)
- RVM is a Ruby Version Manager created by Wayne E. Seguin and is extremely helpful for installing and managing many different versions of Ruby all at once. Sometimes you could be working on a project that requires an older (1.8.7) version of Ruby but also need a new version
(1.9.3) for one of your newer projects. This is a problem that RVM solves beautifully.
- Another situation could be that you want to have different sets of gems on the same version of Ruby but don’t want to have to do deal with Gem Conflict Hell. RVM has gemsets for this. This is a feature you wouldn’t have if you used the packaged Ruby.
- With git-core and curl installed we’ll be able to install RVM with this command: => Run this command in terminal bash < <(curl –s https://rvm.beginrescueend.com/install/rvm) =>The beautiful part of this is that it installs Ruby to our home directory, providing a sandboxed
environment just for us.
- Once that is done add following line to your
~/.bashrc file. => echo ‘[[ -s
$HOME/.rvm/scripts/rvm” ]] && source “$HOME/.rvm/scripts/rvm”‘ >> ~/.bashrc //.bashrc file is responsible for setting up the bash session
- Then we’ll need to reload ~/.bashrc file,which can be done using this small command. => . ~/.bashrc => After using above command,if error comes i.e. rvm(command not found) etc…Then simply close this terminal and start again(Believe me,few times such things do work!!!)
- Next we have to see what are the things required by RVM to install Ruby on Rails..Just use:- => rvm requirements //this will show all the packages required to be installed before,few of which we may have already installed.
To install all the required packages mentioned by rvm requirements,just run following command:- =>sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core //please note these all should be contained in single line,otherwise zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev //few packages may not get installed.
libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
Installing Ruby and Rails
- With RVM and packages installed,we can install ruby using :- => rvm install 1.9.3 //this will install ruby with 1.9.3 version and it takes a little time to get installed. Be patient.
- With RVM installed,we can use that particular version to be used:- => rvm use 1.9.3 //now the ruby 1.9.3 will be used as a ruby version
- To check the version of the ruby version installed:- => ruby -v //check the current version being used
- To make a particular version to be used as default,we can use:-
=> rvm –default use 1.9.3
- As we have installed ruby in our home directory,we don’t need to use sudo command for rails installation. Simply type following command:-
- gem install rails -v 3.0.9 //This will install 3.0.9 version. Any suitable version can be downloaded by just mentioning the
- //It will also install the rails gem and the other 22 gems that it and its dependencies depend on, including Bundler.
Well,Thats it! Enjoy coding!