Ruby on Rails

How to Install Ruby on Rails on CentOS 8 with RVM

Welcome to the Greenhost.Cloud blog! In today’s post, we’ll walk you through the process of installing Ruby on Rails on a CentOS 8 system using RVM (Ruby Version Manager). Rails is a powerful web application framework that follows the MVC (Model-View-Controller) architecture, making it easy to develop and deploy scalable web applications.

Let’s get started!

Prerequisites

Before you dive into the installation process, ensure that you have:

  1. A CentOS 8 server.
  2. A non-root user with sudo privileges.
  3. A basic understanding of command-line operations.

Step 1: Update Your System

First, it’s always a good practice to update your system to ensure all packages are up to date. Run the following command:

sudo dnf update -y

Step 2: Install Required Dependencies

Next, you need to install some dependencies for Ruby and Rails. Use the following command to install the necessary packages:

sudo dnf install -y curl gcc gcc-c++ make patch
sudo dnf install -y openssl-devel readline-devel zlib-devel

These packages are essential for compiling Ruby and managing its dependencies.

Step 3: Install RVM (Ruby Version Manager)

RVM allows you to manage multiple Ruby versions efficiently. You can install it with the following commands:

  1. First, download and install the GPG keys used to verify RVM:
   gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 409B6B1796C7D1D9A6D7A64E6A8A7B74B8F58F9
  1. Next, install RVM:
   curl -sSL https://get.rvm.io | bash -s stable
  1. Load RVM into your shell session:
   source ~/.bashrc
  1. You can verify the installation of RVM by checking the version:
   rvm --version

Step 4: Install Ruby

With RVM installed, the next step is to install Ruby. To do this, you can choose a specific Ruby version or the latest stable version with the command below:

rvm install ruby --latest

To set the installed Ruby version as the default, run:

rvm use ruby --default

You can confirm your Ruby installation by checking the version:

ruby -v

Step 5: Install Rails

Now that Ruby is ready, it’s time to install Rails. Within your terminal, run:

gem install rails

You can verify that Rails was installed correctly by checking its version:

rails -v

Step 6: Create a New Rails Application

With Rails installed, let’s create a new Rails application to ensure everything is working smoothly. Use the following command to create a new application named myapp:

rails new myapp

Navigate to your application directory:

cd myapp

To run your Rails application, start the Rails server:

rails server

You should see output indicating that your server is running, typically on http://localhost:3000. Open a web browser and visit this URL to see the default Rails welcome page.

Step 7: Configure Database (Optional)

By default, Rails configurations use SQLite3 as the database system. If you require a different database (like PostgreSQL or MySQL), you’ll need to install the necessary database gems and set up the database configuration. Adjust the Gemfile and create the necessary databases accordingly.

Conclusion

Congratulations! You have successfully installed Ruby on Rails on CentOS 8 using RVM. You’re now ready to start building amazing web applications with Rails.

Happy coding! 🚀