Ruby on Rails Is a free and open source web application framework that makes building web applications easier and faster. There are hundreds of thousands of popular applications, such as campBasecamp, GitHub, Shopify, Airbnb, Twitch, SoundCloud, Hulu, Zendesk, Square, Highrise, many of which are built using Ruby on Rails. This tutorial shows how to install Ruby on Rails on CentOS 7 and Ubuntu 18.04 LTS server. Also, the installation instructions below should work on other DEB and RPM based distributions.
Install Ruby on Rails
Update and upgrade your Ubuntu system using the following commands:
$ sudo apt-get update
$ sudo apt-get upgrade
On CentOS, execute the following:
$ sudo yum update
Next install RUhVIron Manager (soon RVM). This is a command line tool used to easily install, manage and operate multiple Ruby environments.
You need to download and add the RVM public key. For that, install curl First the package.
$ sudo yum install curl
$ sudo apt-get install curl
Next, run the following commands one at a time to download and add the RVM public key:
$ curl -#LO https://rvm.io/mpapis.asc
$ gpg --import mpapis.asc
Download the RVM installer script using the following command:
$ curl -sSL https://get.rvm.io | bash -s stable
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 output above, there is the following line “To start using RVM, you need to run` source / home / sk / .rvm / scripts / rvm`. “:
Therefore, execute the command to set the RVM environment path.
$ source ~/.rvm/scripts/rvm
This line may be different for RPM based systems. Check the output and execute the command accordingly. On CentOS 7 OS, 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 the RVM dependencies:
$ rvm requirements
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.
Completed Ruby on Rails prerequisites.
Go ahead and install Ruby and Rails.
Now, use the command to find the available Ruby version:
$ 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[.10] [ruby-]2.2[.7] [ruby-]2.3[.4] [ruby-]2.4[.1] ruby-head # for forks use: rvm install ruby-head-
--url https://github.com/github/ruby.git --branch 2.2 # JRuby jruby-1.6[.8] jruby-1.7[.27] jruby[-220.127.116.11] 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 a Ruby version such as 2.4.1, run the following command from a terminal:
$ rvm install 2.4.1
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, use the command to set the default version of Ruby.
$ rvm use 2.4.1 --default
To check which Ruby version you have installed:
$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
that’s it. Next, you need to install Rails.
Rails can be installed using the following command:
$ gem install rails
The above command will install the latest Rails version. You can also install a specific version, such as 4.2.6, as follows:
$ gem install rails -v 4.2.6
To view the version of Rails installed, run:
$ rails -v
that’s it. Ruby on Rails is installed on CentOS 7 and Ubuntu 18.04 LTS Server Edition. For more information on setting up a Ruby and Rails development environment, follow the link at the end of this tutorial.
If you find this tutorial useful, please share it on social and professional networks and support OSTechNix.
Things better for the future. stay tuned!