Back to the Basics: Setting Up Desktop Ubuntu for Rails | NetEngine

Back to the Basics: Setting Up Desktop Ubuntu for Rails

I’m sure this is one of thousands out there that gives a step by step instruction on how to setup a dev environment in Ubuntu for Rails. This is more of a personal preference on setting up my dev box which includes installing terminator, vim and a few other goodies that I always find myself googling when I’ve reinstalled a new ubuntu version. I hope this helps someone without a mac out there :D



Step 1: Installing Ubuntu

Download the latest ubuntu version. As of this writing, the latest version is 14.04, Trusty Tahr. This is also a long term support (LTS) version which means that this version will continue to receive security updates for 5 years compared to non-LTS version which only receive security updates for 1.5 years. There’s a list of releases and when their support date ends in the ubuntu wiki.

Personally, I always install ubuntu using a usb stick. There’s a quick howto from the official ubuntu wiki so please check that out.

Once ubuntu is installed, you’re done with the longest part of this process :)

Step 2: Installing Git

Git is now the de facto standard for version management. It’s also required by some of the items that we’ll install so we need to install this first. To install git, just open a terminal and run

sudo apt-get install git-core

Step 3: Installing Terminator

I actually don’t remember when/why I started using 4 terminals when coding.


I use one window for running the rails server. The main purpose of this one is for debugging purposes. If you have 3 other windows where you can open other files, you can easily see where/why/what a methods/variables are called/defined.

Usually, the other window is used for a rails console or running a background job or running a test. The other 2 windows are where I really open files for coding.

To manage these terminals, I use an application called terminator. Install it using

sudo apt-get install terminator

Step 4: Installing Vim

I use vim for editing files. I don’t use any plugin manager for vim, yet but if you want to use one, I suggest using vundle.

sudo apt-get install vim

Step 5: Installing RVM

In NetEngine, most of the developers are using rbenv as the ruby version manager. I prefer rvm simply because it’s more intuitive for me. The big disadvantage of rvm over rbenv is its installation process. If you look at the installation wiki on the rvm site, there are a lot of things you need to consider when installing rvm. The following code installs rvm for a single user

\curl -sSL | bash -s -- --ignore-dotfiles
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
source $HOME/.rvm/scripts/rvm

Once that’s done, install the latest ruby version using rvm install ruby. If you need to install a specific version, you can check the list of versions available to install using rvm list known. To install MRI version 2.1.2 and make it the default version, use the following

rvm install 2.1.2
rvm use 2.1.2 --default

If you’re running rails 2 and you get an undefined method 'source_index' for Gem:Module, you need to downgrade the rubygems version. Use the following command to do so

rvm rubygems 1.8.25 --force

Step 6: Installing Dotfiles

We all want a personal touch/configuration on our dev box. One really good way to save these settings is to create a dotfiles repo in github and push your files in the repo. I suggest you create the files without the dot at the start and just symlink it.

git clone ~/dotfiles
ln -s ~/dotfiles/vim/vimrc ~/.vimrc
ln -s ~/dotfiles/bash/bashrc ~/.bashrc
ln -s ~/dotfiles/bash/terminator_config ~/.config/terminator/config
ln -s ~/dotfiles/bash/git_bash_prompt ~/.git_bash_prompt
ln -s ~/dotfiles/git/gitignore ~/.gitignore
ln -s ~/dotfiles/git/gitconfig ~/.gitconfig
ln -s ~/dotfiles/gem/gemrc ~/.gemrc

Step 7: Install Packages

The following packages are most likely to be used (except heroku) when you’re developing a rails app so install them

Step 8: Creating a Postgresql User

Whenever I install postgresql, I’ve always had to allot time to searching for a way to create a postgresql user. Not anymore. In order to let rails create/drop the database for you (by running rake commands), you have to setup the user permissions. Usually, it’s the name of the user logged in to the account so we’ll do that.

sudo -u postgres createuser --superuser jim
sudo -u postgres psql
  >> \password jim

The first command creates a superuser called jim. The second one logs you in to the postgresql client which we want in order to change the password for the just created user.

Step 9: Installing Bundler and Rails

Just use the gem command to install rails and bundler

gem install rails bundler

And that’s it! You can now run rails new blog to start using Rails. There’s a really informative guide created by the Rails team so check that out.