Installing RVM, Ruby, Rails and MySQL on Ubuntu

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp

This guide will help you install and set up ruby 1.9.2, RVM, Rails and MySQL on Ubuntu machine. If you are not using Ubuntu then don’t try this method to install rails.



Before starting the installation we will run the sudo apt-get update command so that we have the latest sources. After this the first step is to install Git, curl and build-essential. These packages are required for installing and using RVM. To install these we use the command:

sudo apt-get install build-essential git-core curl

After installing these packages we will install RVM. RVM is Ruby Version Manager created by Wayne E. Seguin. RVM is extremely helpful for installing and managing many different versions of Ruby. Sometimes we need to work on different versions of Ruby in projects so RVM is best for managing different versions of Ruby. We will install RVM with this command:

bash -s stable < <(curl -s

After installation we need to load RVM by using this command: 

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] &&source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc 

Once loaded and ~/.bashrc is added to the line, we can reload the ~/.bashrc by this simple command: 

. ~/.bashrc 

The next step is to know about the packages we need to install for Ruby to work. Here is the command that will tell us about the packages that we need to install: 

rvm requirements

The command will show different packages that we need to install. We will install the packages using this command: 

sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core 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 

To install all the packages this command must be written on a single line, otherwise some of the packages will not be installed. 


Now the installation of RVM is completed so we can easily install any version of Ruby by using this simple command:

rvm install 1.9.2

This command will take some time and will install the mentioned version of ruby. After the installation we must tell RVM to make our required version as default and useable for us. We will use the command: 

rvm --default use 1.9.2 


Now RVM and Ruby is installed the next step is to install Rails. We will use the simple command:

gem install rails -v 3.0.10 

We will not use sudo to install rails because RVM is installed in our home directory. 


Now the installation of Rails is completed and we will install MySQL. Before installing MySQL gem we need to install libmysqlclient-dev package. We will use the command:  

sudo apt-get install mysql-server mysql-client libmysql-ruby libmysqlclient-dev

After installing these packages we will install MySQL gem by using this simple command:

sudo gem install mysql

Now our installation is complete. If anyone has any question, you can ask here. RVM is very powerful tool and it comes in handy for Ruby development. It’s better to use RVM instead of the packages from apt.