How to Install Ruby on Rails 5 on CentOS/RHEL

In this tutorial, How to install Ruby on Rails 5 on Centos . Ruby on Rails is a web application framework.

Ruby on Rails Installation

The first, Have install Ruby refer to here and Install MariaDB database.

The second, Installing other required packages as below.

[vagrant@DevopsRoles ~]# yum --enablerepo=epel,centos-sclo-rh -y install rh-ruby23-ruby-devel nodejs gcc make libxml2 libxml2-devel mariadb-devel zlib-devel libxslt-devel

Install Ruby on Rails 5.

[vagrant@DevopsRoles ~]# gem install bundler 
[vagrant@DevopsRoles ~]# gem install nokogiri -- --use-system-libraries 
[vagrant@DevopsRoles ~]# gem install rails --no-ri --no-rdoc 
[vagrant@DevopsRoles ~]# rails -v 

Example, create an application.

[vagrant@DevopsRoles ~]# gem install mysql2 --no-ri --no-rdoc -- --with-mysql-config=/usr/bin/mysql_config 
[vagrant@DevopsRoles ~]# rails new SampleApp -d mysql 
[vagrant@DevopsRoles ~]# cd SampleApp 
[vagrant@DevopsRoles SampleApp]# vi config/database.yml

The content in file “database.yml” as below

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password: password   # MariaDB password
  socket: /var/lib/mysql/mysql.sock

Create a test application

[vagrant@DevopsRoles SampleApp]# rails db:create 
[vagrant@DevopsRoles SampleApp]# rails generate scaffold devapp name:string title:string body:text 
[vagrant@DevopsRoles SampleApp]# rails db:migrate 
[vagrant@DevopsRoles SampleApp]# rails server --binding=0.0.0.0 

The result, Access to the “http://(server’s hostname or IP address):3000/ and “http://(server’s hostname or IP address):3000/testapps/

You have installed Ruby on Rails 5 on CentOS/RHEL ? . Now let us begin Programming Ruby 🙂

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

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.