Ruby on Rails (Rails) is a popular open-source web application framework that simplifies building dynamic websites. Installing Rails on a Linux server requires Ruby, Node.js, Yarn, and a database system. This guide covers everything for Debian, Ubuntu, and CentOS.
Table of Contents
Prerequisites
Before installing Rails, ensure you have:
-
A server running Debian 12/Ubuntu 22.04/CentOS 9
-
Root or sudo privileges
-
At least 2GB RAM (4GB recommended for production)
-
Basic knowledge of command-line operations
Rails requires Ruby 3.x, Node.js, Yarn, and a database like MySQL or PostgreSQL.
Step 1: Update Your System
Update system packages:
Debian/Ubuntu:
CentOS:
Step 2: Install Dependencies
Install essential libraries:
Debian/Ubuntu:
CentOS:
Step 3: Install Ruby
Install Ruby using rbenv (recommended for managing Ruby versions):
Step 4: Install Node.js and Yarn
Rails requires a JavaScript runtime:
Debian/Ubuntu:
CentOS:
Verify installations:
Step 5: Install Rails
Install Rails via gem:
Step 6: Install Database (MySQL/PostgreSQL)
MySQL (Debian/Ubuntu):
PostgreSQL (Debian/Ubuntu):
For CentOS, replace apt install with dnf install and service names accordingly.
Step 7: Create a New Rails Application
Create a new Rails project with a MySQL database:
Step 8: Configure Rails Database
Edit config/database.yml with your database credentials:
Create the database:
Step 9: Start Rails Server
Start the Rails server:
Step 10: Access Your Rails Application
Open your browser and navigate to:
You should see the Rails welcome page.
Conclusion
Congratulations! Ruby on Rails is now installed on Debian, Ubuntu, or CentOS. You can now:
-
Build web applications quickly
-
Integrate with databases like MySQL or PostgreSQL
-
Deploy Rails applications to production servers