Install Ruby on Rails In CentOS And Ubuntu

install ruby on rails

Ruby on Rails is a free, open source web application framework that allows you to build web applications more easily and quickly. There are hundreds of thousands popular applications such as Basecamp, GitHub, Shopify, Airbnb, Twitch, SoundCloud, Hulu, Zendesk, Square, Highrise, and many are built using Ruby on Rails. In this tutorial, we will see how to install Install Ruby on Rails on CentOS 7 and Ubuntu 18.04 LTS server. Also, the installation steps given below should work on other DEB and RPM based distributions.

Install Ruby on Rails

Prerequisites

Update and upgrade your Ubuntu system with command:

$ sudo apt-get update
$ sudo apt-get upgrade

On CentOS, run:

$ sudo yum update

Then install Ruby enVironment Manager(shortly RVM). It is a command line tool that can be used to easily install, manage, an work with multiple Ruby environments.

We need to download and add RVM public key.

To do so, install curl package first.

On CentOS:

$ sudo yum install curl

On Ubuntu:

$ sudo apt-get install curl

Now, run the following commands one by one to download and add RVM public key:

$ curl -#LO https://rvm.io/mpapis.asc
$ gpg --import mpapis.asc

Download RVM installer script using command:

$ curl -sSL https://get.rvm.io | bash -s stable

Sample output:

Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
gpg: Signature made Monday 11 September 2017 02:29:21 AM IST
gpg: using RSA key E206C29FBF04FF17
gpg: Good signature from "Michal Papis (RVM signing) <[email protected]>" [unknown]
gpg: aka "Michal Papis <[email protected]>" [unknown]
gpg: aka "[jpeg image of size 5015]" [unknown]
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/sk/.rvm/archives/rvm-1.29.3.tgz'

Installing RVM to /home/sk/.rvm/
 Adding rvm PATH line to /home/sk/.profile /home/sk/.mkshrc /home/sk/.bashrc /home/sk/.zshrc.
 Adding rvm loading line to /home/sk/.profile /home/sk/.bash_profile /home/sk/.zlogin.
Installation of RVM in /home/sk/.rvm/ is almost complete:

* To start using RVM you need to run `source /home/sk/.rvm/scripts/rvm`
 in all your open shell windows, in rare cases you need to reopen all shell windows.

As you noticed in the above output, there is a line that says “To start using RVM you need to run `source /home/sk/.rvm/scripts/rvm`”:

So, let us run that command to set the RVM environment path:

$ source ~/.rvm/scripts/rvm

On RPM based systems, this line might be different. Check on your output and run the command accordingly. In my CentOS 7 OS I got – To start using RVM you need to run `source /etc/profile.d/rvm.sh`.

So, I ran the following command:

$ source /etc/profile.d/rvm.sh

After adding the RVM path, run the following command to install RVM dependencies.

$ rvm requirements

Sample output:

Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system ..
.
Installing required packages: g++, gcc, make, libc6-dev, libreadline6-dev, zlib1g-dev, libssl-dev, libyaml-dev, libsqlite3-dev, sqlite3, autoconf, libgmp-dev, libgdbm-dev, libncurses5-dev, automake, libtool, bison, pkg-config, libffi-dev...............................
Requirements installation successful.

We have completed the prerequisites for Ruby on Rails.

Let us go ahead and install Ruby and Rails.

Install Ruby

Now, let us find out the available Ruby versions using command:

$ rvm list known

Sample output:

# 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[.10]
[ruby-]2.2[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]
ruby-head

# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2

# JRuby
jruby-1.6[.8]
jruby-1.7[.27]
jruby[-9.1.13.0]
jruby-head

# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.84]
rbx-head

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1.2.0
mruby-1[.3.0]
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Topaz
topaz

# MagLev
maglev[-head]
maglev-1.0.0

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]
ironruby-head

To install any Ruby version, for example 2.4.1, run the following command from Terminal:

$ rvm install 2.4.1

Sample output:

Searching for binary rubies, this might take some time.
No binary rubies available for: ubuntu/18.04/x86_64/ruby-2.4.1.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system...
Installing required packages: libreadline6-dev...
Requirements installation successful.
Installing Ruby from source to: /home/sk/.rvm/rubies/ruby-2.4.1, this may take a while depending on your cpu(s)...
ruby-2.4.1 - #downloading ruby-2.4.1, this may take a while depending on your connection...
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
100 11.9M 100 11.9M 0 0 74477 0 0:02:48 0:02:48 --:--:-- 88459
ruby-2.4.1 - #extracting ruby-2.4.1 to /home/sk/.rvm/src/ruby-2.4.1....
ruby-2.4.1 - #applying patch /home/sk/.rvm/patches/ruby/2.4.1/random_c_using_NR_prefix.patch.
ruby-2.4.1 - #configuring..................................................................
ruby-2.4.1 - #post-configuration..
ruby-2.4.1 - #compiling.......................................................................-
ruby-2.4.1 - #installing...........
ruby-2.4.1 - #making binaries executable..
ruby-2.4.1 - #downloading rubygems-2.6.14
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
100 751k 100 751k 0 0 46591 0 0:00:16 0:00:16 --:--:-- 44278
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.4.1 - #extracting rubygems-2.6.14....
ruby-2.4.1 - #removing old rubygems.........
ruby-2.4.1 - #installing rubygems-2.6.14...........................
ruby-2.4.1 - #gemset created /home/sk/.rvm/gems/[email protected]
ruby-2.4.1 - #importing gemset /home/sk/.rvm/gemsets/global.gems..............................|
ruby-2.4.1 - #generating global wrappers........
ruby-2.4.1 - #gemset created /home/sk/.rvm/gems/ruby-2.4.1
ruby-2.4.1 - #importing gemsetfile /home/sk/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.4.1 - #generating default wrappers........
ruby-2.4.1 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.4.1 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri

Finally, set Ruby default version using command:

$ rvm use 2.4.1 --default

To find out the installed Ruby version, run:

$ ruby -v

Sample output:

ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

That’s it. Next, we need to install Rails.

Install Rails

To install Rails, run:

$ gem install rails

The above command will install the most recent Rails version. You can also install a specific version, for example 4.2.6, like below.

$ gem install rails -v 4.2.6

To view the installed version of Rails, run:

$ rails -v

Sample output:

Rails 5.2.0

That’s it. Ruby on Rails has been installed in CentOS 7 and Ubuntu 18.04 LTS server editions. For more details about setting up Ruby and Rails development environment, visit the link given at the end of this tutorial.

If you find this tutorial useful, please share it on your social, professional networks and support OSTechNix.

More good stuffs to come. Stay tuned!

Cheers!

Reference links:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...

1 Response

  1. Craig Hibbard says:

    Don’t like adding keys that specifically say they’re not trusted. Don’t like having to use curl to get the programs from some site (rvm.io) I’ve never heard of instead of a repo I trust. Don’t like that the update wants me to enter my password as part of the script (not a shell prompt, it’s from the script). Too bad, really.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.