Ruby on Rails deployment on Ubuntu Server

Ruby on Rails is a web application framework that enables you to develop web applications. It uses the Mobile-View-Controller (MVC) mechanism by providing default structures for the databases, web services and web pages. This article will be based on the installation and brief overview of Rails, Ruby, Ruby Version Manager (RVM) and Rubygem. I am using an Ubuntu Server 15.10 for the deployments.


To install Rails, you need to have Ruby which is an open source programming language. There are different ways to install Ruby. You can install it with your apt-get or yum tools which will not give you the latest version by default. You can download and compile it from source or you can also use the RVM Ruby Version Manager. The RVM permits you to switch between environments and different Ruby versions within the same machine easily. The community of Ruby developers is moving at a fast pace. It's very difficult to manage your Ruby applications without having proper control over the different environments especially when an application is migrated from the Dev to Prod environment. There is another tool called Rbenv which can use to switch between environments. Let's install Ruby on Rails! 🙂

1. Basically, an apt-get install ruby will install ruby with all dependencies. However, from the Ubuntu repo, the version is 2.1 To install it with RVM, you need to install RVM itself first. I installed it using CURL

apt-get install curl

2. install mpapis public key as per official documentation.

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

3. Install RVM - stable version. You would notice several dependencies being installed such as g++, gcc, make etc..

curl -sSL | bash -s stable --ruby

4. To start using RVM, you need to run

source /usr/local/rvm/scripts/rvm

5. You can check your RVM version and update your RVM version with the commands below. More information is also available on  GitHub rvm repo

rvm -v

rvm get head

rvm reload

rvm get stable

6. You can check if all dependencies are installed with the command

rvm dependencies

7. Install Ruby with the command

rvm install ruby. 

8. To use the default version of ruby, you just need to do a

rvm use ruby --default. 

Note that when RVM is installed,  by default it installs a version of Ruby.

9. Normally, after installing RVM, RubyGems, which is a package management framework for Ruby will also be installed alongside. Verify it with the command

rvm rubygems current. 

10. However, if you need to upgrade to the latest RubyGems you need to do a

gem update --system. 

11. Rubygem itself can be updated provided you install the rubygems-update gem. Do a

gem install rubygems-update 

12. To install Rails alongside with all documentation

gem install rails

13. At this stage, we have already installed Ruby on Rails on our Ubuntu server. I will now get into some more details. Since we downloaded the default Ruby, through RVM at step 8, you would notice that you do not have the latest Ruby version! To download the latest stable release which is Ruby-2.2.3 at the time I am writing this article.

rvm install 2.2.3

14. You switch on to the new Ruby-2.2.3 with the command

rvm use ruby-2.2.3

15. Right now, I have Ruby-2.2.1 which is the default version that I have to install alongside RVM and Ruby-2.2.3 which I have manually downloaded at step 13. Supposed we have to test an application with Ruby-2.1.7, lets now download another Ruby i.e; Ruby-2.1.7

rvm install 2.1.7

16. Once the Ruby-2.1.7 is downloaded, we switch on to it (see step 14). At this stage, you would also notice that the PATH of your ENV has changed. Each time you change the Ruby version, you would notice a change in the path.

Screenshot from 2015-11-11 18:14:28

17. Assuming we no longer need this version, lets now purge and uninstall Ruby-2.1.7 After uninstalling repeat the version you want to use at step 14

rvm uninstall 2.1.7

There are other tools such as Rbenv and Chruby which you can use instead of RVM to manipulate Ruby version. There are however its pros and cons when it comes to Rbenv VS RVM.