How to Setup and Configure Ruby on Rails with ‘RVM’ on Ubuntu 16.04


In this article, we will learn how to setup and configure Ruby on Rails, which is the most popular stack application used by the developers which is generally used to create sites and web applications. The Ruby is a programming language where the programer’s use with the combination of Rails development frameworks to make the application development fast and simple.

‘RVM’ (Ruby Version Manager) is the command-line tools used to install the Ruby and Rails which also provides a good environment for application development using Ruby on Rails can also provide multiple Ruby environments.

Prerequisites

We needed an Ubuntu 16.04 installed machine with a non-root user.

Installing the ‘RVM’

The easiest way to install the Ruby on Rails with RVM is to run the following command as a non-root user and will be prompted for regular password.

We will use the ‘gpg’ command to contact a public key server and request for the associated key for the given ID.

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
Output:
gpg: directory `/home/ubuntu/.gnupg' created
gpg: new configuration file `/home/ubuntu/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/ubuntu/.gnupg/gpg.conf' are not yet active durin g this run
gpg: keyring `/home/ubuntu/.gnupg/secring.gpg' created
gpg: keyring `/home/ubuntu/.gnupg/pubring.gpg' created
gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net
gpg: /home/ubuntu/.gnupg/trustdb.gpg: trustdb created
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)

Now we will download the RVM script in the /tmp folder

$ cd /tmp

Below is the command to download the script for installing the RVM.

$ \curl -sSL https://get.rvm.io -o rvm.sh

Once downloaded the script we will run the below command to install which will install the stable Rails version and also install the latest stable release of Ruby.

$ cat rvm.sh | bash -s stable --rails
Output:
Downloading https://github.com/rvm/rvm/archive/1.27.0.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.27.0/1.27.0.tar.gz.asc
gpg: Signature made Tuesday 29 March 2016 07:19:47 PM IST using RSA key ID BF04FF17
gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 409B 6B17 96C2 7546 2A17 0311 3804 BB82 D39D C0E3
Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36 166B E206 C29F BF04 FF17
GPG verified '/home/ubuntu/.rvm/archives/rvm-1.27.0.tgz'
Adding rvm PATH line to /home/ubuntu/.profile /home/ubuntu/.mkshrc /home/ubuntu/.bashrc /home/ubuntu/.zshrc.
Adding rvm loading line to /home/ubuntu/.profile /home/ubuntu/.bash_profile /home/ubuntu/.zlogin.
Installation of RVM in /home/ubuntu/.rvm/ is almost complete:
* To start using RVM you need to run `source /home/ubuntu/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.
# ubuntu,
#
# Thank you for using RVM!
# We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.
In case of problems: https://rvm.io/help and https://twitter.com/rvm_io
rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/16.04/x86_64/ruby-2.3.0.tar.bz2
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system....
Installing required packages: libsqlite3-dev, sqlite3, libgmp-dev, libtool, pkg-config........
Requirements installation successful.
ruby-2.3.0 - #configure
ruby-2.3.0 - #download
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 24.8M 100 24.8M 0 0 670k 0 0:00:37 0:00:37 --:--:-- 911k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.3.0 - #validate archive
ruby-2.3.0 - #extract
;ruby-2.3.0 - #validate binary
ruby-2.3.0 - #setup
ruby-2.3.0 - #gemset created /home/ubuntu/.rvm/gems/ruby-2.3.0@global
ruby-2.3.0 - #importing gemset /home/ubuntu/.rvm/gemsets/global.gems..............................
ruby-2.3.0 - #generating global wrappers........
ruby-2.3.0 - #gemset created /home/ubuntu/.rvm/gems/ruby-2.3.0
ruby-2.3.0 - #importing gemsetfile /home/ubuntu/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.3.0 - #generating default wrappers........
Creating alias default for ruby-2.3.0...
..
..
Installing ri documentation for rails-5.0.0.1
Done installing documentation for i18n, thread_safe, tzinfo, concurrent-ruby, activesupport, rack, rack-test, mini_portile2, nokogiri, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubis, actionview, actionpack, activemodel, arel, activerecord, globalid, activejob, mime-types-data, mime-types, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, thor, method_source, railties, bundler, sprockets, sprockets-rails, rails after 72 seconds
36 gems installed
* To start using RVM you need to run `source /home/ubuntu/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.
* To start using rails you need to run `rails new <project_dir>`.

Once the installation is completed, we need to run the below command to add the environments variable and paths

$ source /home/ubuntu/.rvm/scripts/rvm

Now we will check the installation, below is the command to check the installation.

$ rvm
Output:
= rvm
* https://rvm.io/
* http
s://github.com/rvm/rvm/
== DESCRIPTION:
RVM is the Ruby enVironment Manager (rvm).
It manages Ruby application environments and enables switching between them.
== Installation
……
……
Action documentation available with 'rvm help action-name':
alias autolibs cleanup config-get cron current debug disk-usage do docs fetch fix-permissions gemdir gemset gemset/copy get group implode info install list migrate mount notes osx-ssl-certs patchset pkg prepare reinstall remove repair requirements reset rubygems rvmrc rvmrc/to rvmrc/warning snapshot srcdir tools uninstall upgrade use user wrapper
Other topics of documentation available with 'rvm help topic':
alt color upgrade-notes
For additional information please visit RVM's documentation website:
https://rvm.io/
If you still cannot find an answer to your question, find
'wayneeseguin', 'mpapis', 'richo', 'lemoinem' or 'rys' in #rvm on irc.freenode.net:
http://webchat.freenode.net/?channels=rvm

Installing the Specific Versions of Ruby and Rails

If we want to install a specific version of Ruby to meet your requirements, we have to use the bellow commands.

To list the available versions

$ rvm list known

To install the particular version

$ rvm install version_no

To list the installed versions

$ rvm list

To switch to the particular installed versions

$ rvm use ruby_version

As Rails is a gem, we can also install the particular versions to meet our environment, gem is the command to install we can use the below commands to perform the installation.

To list the valid versions of the Rails

$ gem search ‘rails$’ –all

To install the particular version

$ gem install rails –v version_no

To create gemset

$ rvm gemset create new_gemset_name

To specify the Ruby version with the new gemset.

$ rvm ruby_version@new_gemset_name

Installing the Java Runtime

As some of the Rails features depend on the JavaScript Runtime environment, we needed to install the Node.js.

Below is the command to install the Node.js

$ cd /tmp
$ \curl -sSL https://deb.nodesource.com/setup_6.x -o nodejs.sh
$ less nodejs.sh
$ cat /tmp/nodejs.sh | sudo -E bash –
Output:
## Installing the NodeSource Node.js v6.x repo...
## Populating apt-get cache...
+ apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://deb.kamailio.org/kamailio jessie InRelease
Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:5 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease
Reading package lists... Done
W: http://deb.kamailio.org/kamailio/dists/jessie/InRelease: Signature by key E79ACECB87D8DCD23A20AD2FFB40D3E6508EA4C8 uses weak digest algorithm (SHA1)
…
..
Fetched 6,595 B in 9s (680 B/s)
Reading package lists... Done
W: http://deb.kamailio.org/kamailio/dists/jessie/InRelease: Signature by key E79ACECB87D8DCD23A20AD2FFB40D3E6508EA4C8 uses weak digest algorithm (SHA1)
## Run `apt-get install nodejs` (as root) to install Node.js v6.x and npm

Now we can get the Node.js using the apt-get command

$ sudo apt-get install nodejs
Output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
nodejs
0 upgraded, 1 newly installed, 0 to remove and 107 not upgraded.
Need to get 10.1 MB of archives.
After this operation, 50.7 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_6.x xenial/main amd64 nodejs amd64 6.8.1-1nodesource1~xenial1 [10.1 MB]
Fetched 10.1 MB in 37s (272 kB/s)
Selecting previously unselected package nodejs.
(Reading database ... 70921 files and directories currently installed.)
Preparing to unpack .../nodejs_6.8.1-1nodesource1~xenial1_amd64.deb ...
Unpacking nodejs (6.8.1-1nodesource1~xenial1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up nodejs (6.8.1-1nodesource1~xenial1) ...

After this article, you will be able to setup and configure the RVM to install Ruby and Rails, with the JavaScript runtime with multiple Ruby environments.

Updated on: 20-Jan-2020

267 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements