Setting up Ubuntu for Rails Development

Setting up a Rails development environment in Ubuntu is something I frequently do, so rather than reaching for Google each time, I’ll keep a record here. I’ll be setting up Ruby using RVM, Rails, MySQL server, RubyMine and vim-rails. All commands are entered from a bash terminal. You can copy and paste the commands from this post into terminal.


Ensure you have build essentials installed:

sudo apt-get install build-essential


Next, install our dependencies:

sudo apt-get install apache2 vim git curl libmysqlclient-dev mysql-server nodejs 

Ruby Version Manager (RVM)

RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems. Before we can install it, we need to obtain a key using GnuPG 2.0. First make sure GnuPG is installed:

sudo apt-get install gnupg2


Now obtain the key:

gpg2 --keyserver hkp:// --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3


If you have problems installing the key, or the next step fails, don’t worry, the error message from the next step will give alternative instructions on how to get the key. Assuming everything is okay, let’s push on and grab RVM.

curl -L | bash -s stable


Once RVM is installed you need to modify your .bashrc file which is located in your home folder, using the editor of your choice. I’ll be using vim here:

vim ~/.bashrc


Append to the bottom of the file the following before saving and exiting:

source $HOME/.rvm/scripts/rvm 


Exit your terminal and open it again so the .bashrc file gets reloaded, then enter the following command to install rvm dependencies – if you see a colon symbol (:) you will need to enter your password.

rvm requirements --autolibs=enable


We are ready to install ruby. Head over to the official site to find the latest version of Ruby, as of this writing it is 2.4.1 so I’ll be installing that:

rvm install 2.4.1


Instruct RVM to use 2.4.1 and set it as the default version of Ruby:

rvm use --default 2.4.1


Now if you type ruby -v you should see 2.4.1.


Okay, let’s push onto installing Rails. Again, visit the official site to ascertain the latest version, as of this writing it is 5.1.2.

 gem install rails --version=5.1.2 --no-ri --no-rdoc


Why we are at it, we’ll install the MySQL2 gem:

gem install mysql2 --no-ri --no-rdoc


Once that is finished, type rails -v and you should see 5.1.2. That’s it! Rails is up and running and good to go. Next we will configure our editors.

Update: Before proceeding you should now install Yarn and ChromeDriver, see here.


RubyMine is a very capable commercial IDE for Ruby that comes with a 30 day evaluation. I appreciate all the help I can get when developing, so RubyMine is my first choice for Rails development. Head over to JetBrains and download a version for Linux. I typically install 3rd party applications into a folder called Apps in my home directory, so I copy the downloaded file there. Assuming the name of the file is rubymine-2017.1.5.tar.gz I will uncompress it and rename it to rubymine:

tar -xvf rubymine-2017.1.5.tar.gz 
mv rubymine-2017.1.5 rubymine


Now to install it, we need to execute the rubymine script in the bin folder:

cd rubymine/bin


This will launch the graphical installer which is simple enough to follow, just remember to select the Evaluate for Free option on the licensing page. Once RubyMine is installed, you can begin editing your rails project by opening the folder from the RubyMine main screen.


Lastly, if you enjoy using vim, there is an excellent plugin available for Rails development from Tim Pope here. Assuming you have not configured vim yet you can execute the following instructions to install pathogen and vim-rails:


mkdir -p ~/.vim/autoload ~/.vim/bundle
curl -LSso ~/.vim/autoload/pathogen.vim
Initial .vimrc Settings

Next, edit your ~/.vimrc file (vim ~/.vimrc) and add the following:

execute pathogen#infect()
syntax on
filetype plugin indent on
set nu
set ts=2
set sw=2
set softtabstop=2
set colorcolumn=110
highlight colorcolumn ctermbg=darkgray

Finally we can install vim-rails:

cd ~/.vim/bundle
git clone 
vim -u NONE -c "helptags vim-rails/doc" -c q


That’s it we are all up and running!

One thought on “Setting up Ubuntu for Rails Development

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s