Installing Rails on Linux

Learn to install Rails on Linux

Linux has many different distributions, each with its own method of installing software along with various idiosyncrasies around how it behaves. It would be too difficult to cover them all, so in this lesson, we’ll outline how to get a Rails environment running in a virtual machine running Ubuntu Linux. Most of the software we’ll install will be needed on any Linux distribution, so if you aren’t using Ubuntu, hopefully, this will help to know what is needed to set up.

Also note that if you are using Ubuntu but not a virtual machine, some of the behavior might be different, especially if your machine already has some packages installed on it.

With that disclaimer out of the way, our setup will require a few different steps. First, we’ll set up a virtual machine using Vagrant, which you can skip if you already have Linux running on your computer. Then we’ll install some system software that the Ruby and Rails development tools require, before finally installing Ruby and Rails.

Setting up a virtual machine

Vagrant is a system that can manage a virtual computer, and Virtual Box provides that virtual computer. Together, they can mimic a real computer to provide a totally clean, predictable, and isolated environment from your actual computer. We’ll set up the virtual machine with Ubuntu Linux.

Of course, that means that it’s necessary to install both Vagrant and Virtual Box on your computer, and how you do that depends on your operating system! Vagrant provides installation instructions and the best thing to do is to follow the instructions there. Once this is complete, head over to Virtual Box’s installation page and install that on your computer.

With those installed, we’ll create a file to describe how Vagrant should set up your virtual machine. This file is called Vagrantfile. We’ll need to create it somewhere on your computer where you prefer to work, such as your home directory or a subdirectory of it. Locate wherever that is and create Vagrantfile to have the following contents (comments in the code explain what each bit does):

Get hands-on with 1200+ tech skills courses.