How to install Ruby on Rails on Ubuntu

Good Day my dear Linux Yogi’s,

it has been quiet some time till I posted something here and I am in for a treat. I am going to show you how to get the latest version of Ruby and Rails installed by using rbenv. There different way in installing this but in my experience this is the best working method for me.

In order to get started with this task lets ensure that your system is up to date and has all requirement installed for this to work. First off lets run the following commands to get updated.

sudo apt update
sudo apt full-upgrade

Great that took care of that. Next lets get all pre-requirements installed with the following command:

Now you got all the necessary pre-requirement for Ruby on Rails install with rbenv satisfied. Let’s have a look at the version available for installation. Issue the following command:

rbenv install -l

The command above will output a list of all available versions. Currently the latest stable version is 2.4.2. Lets install it with the following commands.

rbenv install 2.4.2
rbenv global 2.4.2

The first command will install Ruby 2.4.2 by using ruby-build and the second command will set and show the Ruby version. You can also execute the command below to see the installed default version.

ruby -v

Before we can install Rails we need to install a Ruby Gem called bundler. Run the following two commands:

echo "gem: --no-document" > ~/.gemrc
gem install bundler

The first command generates a .gemrc configuration file and the second command installs the bundler gem. Now you are ready to install Rails which is a Ruby gem. Execute the following command:

gem install rails

The command above will install automatically the latest stable version of rails and in this case it is version 5.1.4. Each time you install a new version or new gem you should run the following command to make it available:

rbenv rehash

Now issue the following command and it will return the default version that is installed on your system.

rails -v

So you are almost done. Ruby on Rails is not complete without JavaScript. JavaScript is required for some extra features. Issue the following two commands:

cd /tmp
\curl -sSL https://deb.nodesource.com/setup_6.x -o nodejs.sh

Issue the following command to add the Node.js repository to your system which makes it easier to installed the latest Node.js and also keeps it updated as well.

cat /tmp/nodejs.sh | sudo -E bash -

Awesome this is done. Let’s update our repositories and install node.js with the following two commands:

sudo apt update
sudo apt install nodejs

Congratulations you installed Ruby on Rails including Node.js by using rbenv. If you like to keep your rbenv updated just execute the following two commands:

cd ~/.rbenv
git pull

This keeps the rbenv updated and allows you to install newer version of Ruby and Rails.

Thank you for reading this illustration. If you like me to illustrate something you like to see please don’t hesitate to send me an email with my contact form or just leave a comment on my blog.