Blog

Install Ruby on Rails on CentOS 8

 107 total views,  1 views today

In this article, we will learn how to install Ruby on Rails Server on CentOS 8.

Update CentOS 8 Software Packages

:~$ su
:~# dnf update

This will ensure all the security patches have installed correctly.

Install Ruby on Rails Pre-requisites on CentOS 8

First let’s the development pre-requisites

# dnf install -y git zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel

Let’s install node.js

First let’s add NodeSource yum repository in CentOS server

curl -sL https://rpm.nodesource.com/setup_12.x | bash -

Then let’s install the node.js

Node.js

dnf install -y nodejs

Now, let’s install yarn (yarn is a package manager just like npm)

First let’s add the YARN yum repository

curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo

Then, install yarn as shown below

dnf install -y yarn

Install MariaDB Server (optional)

# dnf install -y mariadb-server

Enable MaridDB service

# systemctl enable --now mariadb.service

Configure MariaDB server and set root user password using the following command.

# mysql_secure_installation

Follow the instructions after executing the above command and you will have MariaDB successfully installed.

Install RVM on CentOS

RVM is ruby version manager (you can also use the alternative rbenv)

First, let’s add the RVM ym repository. We are required to add the GPG key for the RVM repo as shown below.

gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

If you face any issues please refer the RVM official documentation at

https://rvm.io/rvm/security

Now, install RVM as follows

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

To set RVM environment for the current session we need to execute the below command

source /etc/profile.d/rvm.sh

Now, RVM should be successfully installed on CentOS.

Now, let’s install Ruby.

Ruby Installation

Before we install ruby, let’s check and resolve any missing pre-requisites for Ruby by using the below rvm command.

rvm requirements

You can check the list of known versions of Ruby by running the below command.

rvm list known

From this list we can install the required version of ruby. We will install the 2.7 version.

rvm install 2.7

By using RVM we can install multiple Ruby environments on the same platform. Therefore we have to set a default version to use.

We can set the default Ruby version by executing the below command on the terminal.

rvm use 2.7 --default

Verify the current Ruby version by running the below command in the terminal.

ruby --version

Now, comes the installation of Ruby on Rails framework.

We can install rails framework by simple executing the below command on the terminal (rails is a ruby gem)

Install Rails

gem install rails

Let’s now verify the version of rails

rails -v

Ruby on Rails uses the default service port 3000. Therefore, we need to allow this port in the firewall.

# firewall-cmd --permanent --add-port=3000/tcp

NOTE: If any errors, troubleshoot please as errors could be very varied due to various factors.

Let’s reload the configuration

# firewall-cmd --reload

Install Required Ruby Gems

First, let’s install Bundler. Bundler provides a consistent environment for Ruby projects by tracking and installing exact gems and versions that are needed by the application.

We can install Bundler by using the gem command as shown below.

# gem install bundler

Our Ruby on Rails server is configured and ready to use now.

Let’s install sqlite3 for development purpose.

SQLITE3

# dnf install sqlite

MariaDB/MySQL Gem

MariaDB uses the mysql gem. So, install it as below.

gem install mysql2

NOTE: Most people use sqlite for development and mariadb/mysql/postgresql for production. But you can use any database for development and a recommendation is to use the same database in development as that of production environment to avoid headaches later.

First Rails Project

To test our rails installation, let’s create a HelloWorld Project.

# rails new HelloWorld 

On successful completion run the below command. Also, watchout your terminal output for additional information.

# cd HelloWorld
# rails s -b 0.0.0.0

If there are no errors the server should start on the below URL

http://yourhostnameORipaddressORlocalhost:3000

NOTE: This article will be updated with more information on addtional packages, rbenv etc.

How useful was this post?

Click on a heart to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Leave a Reply

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