On this tutorial, we will focus on how to install Ruby on Rails on RHEL 9/ CentOS Stream 9. Rails is a web application development framework written in Ruby Programming Language designed to make programming web applications easier by allowing you to write less code and make development more fun. It is an opinionated software with the assumption that there are many options for doing things but there is a ‘best’ way and hence encourages that way while discouraging other alternatives. It includes two major guiding principles which are;

  • Don’t Repeat Yourself (DRY) in terms of writing the same code over and over again.
  • Convention Over Configuration: which follows the best way to achieve things over endless configuration files.

Rails is a full-stack web framework shipped with tools needed to build web apps on both the front and back end. It renders HTML templates, sends and receives emails, updates databases, maintains live pages via WebSockets, stores uploads in the cloud, and provides solid security protections for common attacks. It is focused on compressing the complexity of modern web applications. It includes more unique features;

  • Support different Databases that keep records that make modeling easy.
  • Controllers handle all requests like exposing the domain model to the web.
  • Templates are written in Ruby and HTML.
  • Dispatch route URLs using the routing domain language.

Install Ruby on Rails on RHEL 9/ CentOS Stream 9

Having looked at a brief introduction on Ruby on Rails, we can now embark on the process on how to install Ruby on Rails on RHEL 9/ CentOS Stream 9. We hope that this articles works well on your end.

1. Install Ruby on RHEL 9/ CentOS Stream 9

On this article, we will first focus on how to install Ruby on RHEL 9/ CentOS Stream 9. The following shows the process on how it is done;

Step 1. Install the Required Dependencies

The very first step before you proceed is to enable EPEL Repository on your system to install the latest packages. After that proceed to install the required dependencies by utilizing the command shown below;

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

Install Node.js to make use of Ruby on Rails LTS.

curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -
sudo dnf install -y nodejs

Install Yarn Package required by Ruby on Rails source components.

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

Step 2. Install with Ruby Language with RPM/repo

Once the dependencies have been installed successfully with no errors, you can then continue to install Ruby Programming Language if you do not have it on your system. To do so, use the command;

sudo yum install -y ruby rubygems

Confirm Ruby is installed.

$ ruby -v
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]

Turn off the installation of local documentation for each gem to reduce the time for instilling the gems.

echo "gem: --no-document" > ~/.gemrc

Install the bundler.

sudo gem install bundler

Step 3. Install Ruby with RVM

Install GPG keys for Ruby Version Manager (RVM) using the following command.

[[email protected] ~]$ gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: directory '/home/annalianie/.gnupg' created
gpg: keybox '/home/annalianie/.gnupg/pubring.kbx' created
gpg: key 105BD0E739499BDB: 1 duplicate signature removed
gpg: /home/annalianie/.gnupg/trustdb.gpg: trustdb created
gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <[email protected]>" imported
gpg: key 3804BB82D39DC0E3: public key "Michal Papis (RVM signing) <[email protected]>" imported
gpg: Total number processed: 2
gpg:               imported: 2

Install the latest RVM stable with the following command.

[[email protected] ~]$ \curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
gpg: Signature made Fri 15 Jan 2021 01:46:22 PM EST
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 '/home/annalianie/.rvm/archives/rvm-1.29.12.tgz'
Installing RVM to /home/annalianie/.rvm/
    Adding rvm PATH line to /home/annalianie/.profile /home/annalianie/.mkshrc /home/annalianie/.bashrc /home/annalianie/.zshrc.
    Adding rvm loading line to /home/annalianie/.profile /home/annalianie/.bash_profile /home/annalianie/.zlogin.
Installation of RVM in /home/annalianie/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/annalianie/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM ūüôŹ
Please consider donating to our open collective to help us maintain RVM.

ūüĎČ  Donate: https://opencollective.com/rvm/donate

Load the RVM environment.

source ~/.rvm/scripts/rvm
rvm reload

Verify all dependencies are correctly installed.

$ rvm requirements run
Checking requirements for centos.
Installing requirements for centos.
Installing required packages: ruby..........
Requirements installation successful.

3.1 Install Ruby using RVM

Find the latest version of Ruby with the following command

rvm list known

Install it with the following command

[[email protected] ~]$ rvm install 3.0.4
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/9/x86_64/ruby-3.0.4.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Requirements installation successful.
Installing Ruby from source to: /home/annalianie/.rvm/rubies/ruby-3.0.4, this may take a while depending on your cpu(s)...
ruby-3.0.4 - #downloading ruby-3.0.4, 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 20.1M  100 20.1M    0     0  33.1M      0 --:--:-- --:--:-- --:--:-- 33.1M
ruby-3.0.4 - #extracting ruby-3.0.4 to /home/annalianie/.rvm/src/ruby-3.0.4....|
ruby-3.0.4 - #autogen.sh.
ruby-3.0.4 - #configuring......................................................|
ruby-3.0.4 - #post-configuration..
ruby-3.0.4 - #compiling........................................................-
ruby-3.0.4 - #installing.....................
ruby-3.0.4 - #making binaries executable...
Installed rubygems 3.2.33 is newer than 3.0.9 provided with installed ruby, skipping installation, use --force to force installation.
ruby-3.0.4 - #gemset created /home/annalianie/.rvm/gems/[email protected]
ruby-3.0.4 - #importing gemset /home/annalianie/.rvm/gemsets/global.gems......there was an error installing gem rubygems-bundler
ruby-3.0.4 - #generating global wrappers........
ruby-3.0.4 - #gemset created /home/annalianie/.rvm/gems/ruby-3.0.4
ruby-3.0.4 - #importing gemsetfile /home/annalianie/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-3.0.4 - #generating default wrappers........
ruby-3.0.4 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-3.0.4 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri

Set the latest Ruby version as the default.

rvm use 3.0 --default

Verify the Ruby version.

$ ruby -v
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]

Install the bundler. Turn off local documentation for each gem we install to reduce the installation process then install the bundler.

echo "gem: --no-document" > ~/.gemrc
sudo gem install bundler

Step 4. Install rbenv and Ruby Env’

Use the following commands to install the rbenv environment. This downloads the rbenv and Ruby environment and adds them to the executable path.

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

Verify that rbenv is set up correctly.

$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /home/technixleo/.rbenv/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /home/technixleo/.rbenv/plugins/ruby-build/bin/rbenv-install (ruby-build 20220825)
Counting installed Ruby versions: none
  There aren't any Ruby versions installed under `/home/technixleo/.rbenv/versions'.
  You can install Ruby versions like so: rbenv install 3.1.2
Checking RubyGems settings: OK
Auditing installed plugins: OK

4.1 Install Ruby Versions

To list the available stable versions of Ruby, use the following command.

$ rbenv install -l


Only latest stable releases for each Ruby implementation are shown.
Use 'rbenv install --list-all / -L' to show all local versions

The latest version from the list is 3.1.2. Unfortunately, it does not work with rails to create a database and only accepts 3.0.4 which is the one I will install for this guide.

$ rbenv install 3.0.4

Set the latest version as the default.

rbenv global 3.0.4

Check the Ruby Version.

$ ruby -v
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]

Install the bundler. The process is lengthy, to reduce it off local documentation for each gem we install then install the bundler.

echo "gem: --no-document" > ~/.gemrc
gem install bundler

2. Install Rails on CentOS 9| RHEL 9

Install dependencies required to install Rails using the command;

sudo dnf install ruby -devel

Install Rails with the following command

$ sudo gem install rails
Building native extensions. This could take a while...
Successfully installed websocket-driver-0.7.5
Building native extensions. This could take a while...
Successfully installed nio4r-2.5.8
Successfully installed actioncable-
Successfully installed rails-
4 gems installed

Verify the version of Rails

$ rails -v

Configure Firewall to allow Ruby on rails service.

sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload

Step 5. Create Sample Application

We will now test Ruby on Rails on our system. It uses SQLite as its default database. You can use it in a test environment but it is not recommended in the production environment. We will install MariaDB in our database to use.

Step 5.1 Install Database

Install MariaDB with the following command.

sudo dnf install -y mariadb-server mariadb mariadb-devel

Start and enable the service.

sudo systemctl enable --now mariadb

Secure MariaDB installation with the following command.

$ sudo mysql_secure_installation


In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Install the mysql2 extension.

$ sudo gem install mysql2
Fetching mysql2-0.5.4.gem
Building native extensions. This could take a while...
Successfully installed mysql2-0.5.4
Parsing documentation for mysql2-0.5.4
Installing ri documentation for mysql2-0.5.4
Done installing documentation for mysql2 after 0 seconds
1 gem installed

Step 5.2 Create a Rails Project

Create a new application and change it to the application directory.

rails new rbapp -d mysql
cd rbapp

Edit the database configuration

sudo vi config/database.yml

Update the database user and password

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: password # Replace with MariaDB / MySQL user password
  socket: /var/lib/mysql/mysql.sock

Save and exit the file.

Create the database with the following command

$ rake db:create
Created database 'rbapp_development'
Created database 'rbapp_test'

Step 5.3 Validate Rails Application

Validate the Application by starting it with the following command

$ rails server -b
=> Booting Puma
=> Rails application starting in development 
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.6.5 (ruby 3.0.4-p208) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 2888
* Listening on
Use Ctrl-C to stop

Now go to http://localhost:3000 on your browser to view the following page.

Step 6. Uninstall Rails from CentOS 9| RHEL 9

To uninstall Rails, use the following command

$ gem uninstall rails
Successfully uninstalled rails-

Uninstall the railties with the following command.

$ gem uninstall railties

You have requested to uninstall the gem:

importmap-rails-1.1.5 depends on railties (>= 6.0.0)
stimulus-rails-1.1.0 depends on railties (>= 6.0.0)
turbo-rails-1.1.1 depends on railties (>= 6.0.0)
web-console-4.2.0 depends on railties (>= 6.0.0)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]  y
Remove executables:

in addition to the gem? [Yn]  y
Removing rails
Successfully uninstalled railties-


We have installed Ruby on Rails on RHEL 9|CentOS 9. Ruby on Rails web application framework has the opinion that there is a ‘best’ way to achieve things like having a single, unambiguous, authoritative representation within a system and asks the question of why should you bother with alternatives. It has a simple and fun way of writing code making it easily manageable, extensible and less buggy. Check below for more of our articles;


Please enter your comment!
Please enter your name here