How to Install Ruby on Rails on CentOS 8
Ruby on Rails is a free and open-source web application framework that helps you to create a website with Ruby. Rails is a model–view–controller framework that combines the Ruby programming language with JavaScript, HTML, and CSS to write web applications runs on the webserver and simplifies common repetitive tasks. Rails comes with a set of conventions that helps developers to speed up development without spending a lot of time for file configuration.
In this tutorial, we will show you how to install Ruby on Rails framework on a CentOS 8 server.
Requirements
- A server running CentOS 8.
- A root password is configured on the server.
Install Ruby
The simple and easiest way to install Ruby using the RVM. RVM also known as «Ruby Version Manager» is a command-line tool that can be used to install and manage different Ruby versions from interpreters.
First, install curl and gnupg2 package with the following command:
dnf install curl gnupg2 -y
Next, you will need to import the RVM public key on your system:
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
You should see the following output:
gpg: key 105BD0E739499BDB: 8 signatures not checked due to missing keys gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <[email protected]>" imported gpg: key 3804BB82D39DC0E3: 108 signatures not checked due to missing keys gpg: key 3804BB82D39DC0E3: "Michal Papis (RVM signing) <[email protected]>" not changed gpg: no ultimately trusted keys found gpg: Total number processed: 2 gpg: imported: 1 gpg: unchanged: 1
Next, download and install the latest stable version of RVM using the following command:
curl -sSL https://get.rvm.io | bash -s stable
Once the RVM is installed, you should get the following output:
Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc gpg: Signature made Wednesday 10 July 2019 04:31:02 AM EDT gpg: using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDB gpg: Good signature from "Piotr Kuczynski <[email protected]>" [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: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB GPG verified '/usr/local/rvm/archives/rvm-1.29.9.tgz' Creating group 'rvm' Installing RVM to /usr/local/rvm/ Installation of RVM in /usr/local/rvm/ is almost complete:
Next, activate the RVM environment variable with the following command:
source /etc/profile.d/rvm.sh
Next, install all the Ruby dependencies by running the following command:
rvm requirements
Once all the dependencies are installed, you should see the following output:
Checking requirements for centos. Installing requirements for centos. Installing required packages: patch, autoconf, automake, bison, gcc-c++, libffi-devel, libtool, make, patch, readline-devel, ruby, sqlite-devel, zlib-devel, glibc-headers, glibc-devel, openssl-devel......................................... Requirements installation successful.
You can now list all available Ruby versions with the following command:
rvm list known
You should see the following 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[.10] [ruby-]2.3[.8] [ruby-]2.4[.6] [ruby-]2.5[.5] [ruby-]2.6[.3] [ruby-]2.7[.0-preview1] ruby-head
Now, you can install the Ruby version 2.6.3 using the following command:
rvm install 2.6.3
Next, run the following command to set the version 2.6.3 as the default version:
rvm use 2.6.3 --default
Output:
Using /usr/local/rvm/gems/ruby-2.6.3
You can also verify the installed version of Ruby using the following command:
ruby --version
Output:
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
Install Rails
You can install the latest version of Rails using the gem command as shown below:
gem install rails
After installing Rails, you can check the Rails version with the following command:
rails -v
You should see the following output:
Rails 6.0.2.1
Conclusion
In the above tutorial, you learned how to install Ruby on Rails on a CentOS 8 server. You can now easily install, manage and work with different Ruby versions using RVM. For more information, you can visit the Ruby official documentation at Ruby Doc.