How to Easily Install Rails 7 on CentOS and CentOS 9

How to Easily Install Rails 7 on CentOS and CentOS 9

Welcome to our beginner-friendly tutorial on installing Rails 7 on CentOS and CentOS 9! We’ll guide you through the process in simple steps, using everyday language and a friendly tone. Let’s get started on this journey to building powerful web applications.

What You Need Before Starting

Before diving into Rails 7 installation, make sure you have these essentials ready:

1: Ruby Environment
Set up Ruby using a version manager like RVM or rbenv. This lets you manage different Ruby versions smoothly.

2: Node.js and Yarn
Rails 7 relies on Node.js and Yarn for managing JavaScript assets. Install Node.js from NodeSource repository and Yarn via npm.

3: Database Choice
Decide between SQLite or PostgreSQL based on your project's needs.

Step-by-Step Installation Guide

Step 1: Installing Ruby

Let's start by installing Ruby using RVM. Open your terminal and follow these commands:

				
					sudo yum install curl gnupg2 dirmngr
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
curl -sSL https://get.rvm.io | bash -s stable --ruby
source ~/.rvm/scripts/rvm
rvm install ruby

				
			

After installation, verify Ruby's version with ruby --version.

Step 2: Installing Node.js and Yarn

Next, add the NodeSource repository and install Node.js and Yarn:

				
					curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -
sudo yum install -y nodejs
sudo npm install -g yarn

				
			

Check Node.js and Yarn versions with node --version and yarn --version respectively.

Step 3: Choosing and Setting up the Database

For SQLite, install the necessary packages with sudo yum install sqlite-devel. For PostgreSQL, follow these steps:

				
					sudo yum install postgresql-server postgresql-devel
sudo postgresql-setup initdb
sudo systemctl start postgresql
sudo systemctl enable postgresql

				
			

Step 4: Installing Rails 7

Now, install Rails 7 using gem:

				
					gem install rails

				
			

Verify the installation with rails --version.

Step 5: Creating a New Rails Application

Navigate to your preferred directory and create a new Rails application:

				
					rails new myapp
cd myapp

				
			

Step 6: Configuring the Database

Edit config/database.yml to set up your database. For example, for SQLite:

				
					development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

				
			

For PostgreSQL:

				
					development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  pool: 5
  username: postgres
  password: your_password
  host: localhost

				
			

Step 7: Running Migrations and Starting the Server

Run database migrations to set up your schema:

				
					rails db:migrate

				
			

Start the Rails server:

				
					rails server

				
			

Visit http://localhost:3000 in your browser to see your new Rails application in action!

Congratulations ๐ŸŽ‰, you've successfully installed Rails 7 on CentOS or CentOS 9 and created your first Rails app.
Happy coding! ๐Ÿ˜‰

Sharing is caring!

Leave a Comment

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