Categories Tutorials

Install Ruby on Rails on Ubuntu 16.04

Ruby on Rails is a full stack web application framework which provides default structures for databases, web services and web pages. It is used by many developers since it makes the application development very simple. In this tutorial we will show you how to install Ruby on Rails on a Linux VPS running Ubuntu 16.04 as an operating system.

First of all, you need to connect to your server via SSH as root or as a regular system user and update all your system software to the latest version available. For that purpose you can run the following command:

apt-get update && apt-get -y upgrade

One way of installing Ruby on Rails on an Ubuntu VPS is by using the Ruby Version Manager, or shortly RVM. We will use RVM to install Ruby on Rails in this tutorial. In order to install RVM on your server, you can use the following commands:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
cd /tmp && \curl -sSL https://get.rvm.io -o rvm.sh
cat /tmp/rvm.sh | bash -s stable

If you get something like this:

-bash: curl: command not found

that means curl is not installed on your server. Go ahead and install curl by using the command below:

apt-get install curl

To start using RVM you need to run:

source /usr/local/rvm/scripts/rvm

To list which Ruby versions are available for installation, run the following command:

rvm list known

The list should look like the following one:

# rvm list known
# MRI Rubies
[ruby-] 1.8.6 [-p420]
[ruby-] 1.8.7 [-head] # security released on head
[ruby-] 1.9.1 [-p431]
[ruby-] 1.9.2 [-p330]
[ruby-] 1.9.3 [-p551]
[ruby-] 2.0.0 [-p648]
[ruby-] 2.1 [.8]
[ruby-] 2.2 [.4]
[ruby-] 2.3 [.0]
[ruby-] 2.2-head

To install a specific version of Ruby (for example 2.3.0) you can use the command:

rvm install 2.3.0

Rails is a Ruby gem and different versions of Rails are available for installation too. To install Rails you can use the command below:

gem install rails

To verify the installation as well as to check what version of Ruby you are currently using, you can use the command:

ruby --version

The output should be similar to the following one:

# ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

To do the same for Rails, use the command:

rails -v

The output should be similar to the following one:

# rails -v

Now you are ready to start with your first Ruby on Rails project. Create a new Ruby on Rails application in your home directory:

cd ~
rails new firstApp

This should take no longer than a minute. Once your new Ruby on Rails application is created, you can start developing the application. There are new guides for Rails 5.0 which will help you understand how all of the pieces fit together. Good Luck!

Of course you don’t have to do any of this if you use one of our Linux VPS hosting services, in which case you can simply ask our expert Linux admins to install Ruby on Rails for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.