RHEL BasedRocky Linux

How To Install Ruby on Rails on Rocky Linux 10

Install Ruby on Rails on Rocky Linux 10

Ruby on Rails, often simply called Rails, is a powerful web application framework that has revolutionized web development with its elegant syntax and convention-over-configuration philosophy. When combined with Rocky Linux 10’s enterprise-grade stability and security features, Rails creates an ideal environment for building robust, scalable web applications. This comprehensive guide walks you through the complete installation process, from system preparation to deploying your first Rails application.

Whether you’re a seasoned developer or just starting your Rails journey, this tutorial provides detailed instructions, troubleshooting tips, and best practices to ensure a successful installation. By the end of this guide, you’ll have a fully functional Ruby on Rails development environment running on Rocky Linux 10.

Understanding Ruby on Rails and Rocky Linux 10

What is Ruby on Rails?

Ruby on Rails is an open-source web application framework written in the Ruby programming language. Rails follows the Model-View-Controller (MVC) architectural pattern, which separates application logic into three interconnected components. This separation promotes organized, maintainable code that scales effectively as applications grow.

The framework emphasizes convention over configuration, meaning developers spend less time writing configuration files and more time building features. Rails includes everything needed to create database-backed web applications, including an Object-Relational Mapping (ORM) system called Active Record, built-in testing frameworks, and powerful routing capabilities. This philosophy makes Rails particularly attractive for rapid prototyping and agile development methodologies.

Rocky Linux 10 Overview

Rocky Linux 10 serves as a community-driven, enterprise-grade Linux distribution that maintains binary compatibility with Red Hat Enterprise Linux (RHEL). This compatibility ensures that applications and configurations tested on RHEL will work seamlessly on Rocky Linux 10, making it an excellent choice for production environments.

The distribution features the DNF package manager, which provides reliable dependency resolution and package management capabilities. Rocky Linux 10’s focus on security includes regular security updates, SELinux integration, and comprehensive firewall management tools. These features create a stable, secure foundation for hosting Ruby on Rails applications in both development and production environments.

Prerequisites and System Requirements

Hardware Requirements

Before beginning the installation process, ensure your system meets the minimum hardware specifications. Your Rocky Linux 10 server should have at least 2GB of RAM for basic Rails development, though 4GB or more is recommended for optimal performance. Storage requirements include a minimum of 10GB of available disk space for the operating system, Ruby installation, gems, and development tools.

For production environments or intensive development work, consider allocating additional resources. A multi-core processor will significantly improve compilation times when installing Ruby and Rails gems that require native extensions.

Software Prerequisites

This installation guide assumes you have a fresh Rocky Linux 10 installation with basic system configuration completed. You’ll need access to a user account with sudo privileges to install packages and modify system configurations. Administrative access is essential for installing development tools, managing services, and configuring the system environment.

Ensure your system has a reliable internet connection for downloading packages, Ruby versions, and Rails gems throughout the installation process. Basic familiarity with the Linux command line interface will help you follow the instructions effectively, though all commands are explained in detail.

System Preparation and Updates

System Updates

Begin by updating your Rocky Linux 10 system to ensure you have the latest packages and security patches. The DNF package manager provides a straightforward method for maintaining system updates. Execute the following command to refresh the package repository metadata and install available updates:

sudo dnf update -y

This command downloads and installs all available updates automatically. The process may take several minutes depending on your internet connection and the number of packages requiring updates. System updates are crucial for security and compatibility, as newer versions of development tools often require current system libraries.

After the update process completes, consider rebooting your system to ensure all kernel and system-level updates take effect properly. While not always necessary, a reboot guarantees that all services are running with updated configurations.

Installing Development Tools

Rocky Linux 10 includes a convenient package group called “Development Tools” that installs essential compilation tools and libraries needed for building software from source. This group includes GCC, make, autotools, and other fundamental development utilities required for Ruby compilation and gem installation with native extensions.

sudo dnf groupinstall "Development Tools" -y

The Development Tools group installation provides the foundation for compiling Ruby from source and installing Rails gems that require compilation. Without these tools, many Ruby gems will fail to install, particularly those that interface with system libraries or include C extensions for performance optimization.

Installing Required Dependencies

Core Development Libraries

Ruby on Rails applications require numerous system libraries for full functionality. These dependencies support database connectivity, SSL encryption, XML processing, and other essential features. Install the complete set of required libraries using the following command:

sudo dnf install -y gcc-c++ patch readline readline-devel zlib zlib-devel \
  libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake \
  libtool bison sqlite-devel

Each of these packages serves specific purposes in the Rails ecosystem. OpenSSL development headers enable secure database connections and HTTPS support. SQLite development files provide the default database backend for Rails applications. Readline libraries enhance the interactive Ruby console experience with command history and editing capabilities.

YAML processing libraries handle configuration files and data serialization that Rails uses extensively. The FFI library enables Ruby to interface with C libraries dynamically, while compression libraries support asset processing and data handling throughout the framework.

Additional Required Packages

Several additional packages enhance the development environment and provide tools commonly used in Rails development workflows. Git version control integration is essential for managing Rails applications and tracking changes throughout the development process.

sudo dnf install -y git curl wget gnupg2

Git enables version control and collaboration on Rails projects. Most Rails applications use Git repositories for source code management, making it an essential tool for any Rails developer. cURL and Wget facilitate downloading resources and testing API endpoints during development.

GnuPG provides cryptographic verification for downloaded software, ensuring the integrity and authenticity of Ruby version managers and other development tools. This verification process is particularly important when installing software from third-party sources.

Ruby Installation Methods

Method 1: AppStream Repository Installation

Rocky Linux 10’s AppStream repository includes packaged versions of Ruby that provide a quick installation option. This method offers simplicity and integration with the system package manager, making it suitable for users who prefer distribution-packaged software.

sudo dnf install ruby ruby-devel ruby-doc

The repository installation includes the Ruby interpreter, development headers, and documentation in a single, coordinated package set. This approach ensures compatibility with other system packages and provides automatic security updates through the normal system update process.

However, repository versions often lag behind the latest Ruby releases, potentially limiting access to newer language features and performance improvements that Rails applications might benefit from.

Method 2: RVM (Ruby Version Manager) Installation

Ruby Version Manager (RVM) provides the most flexible approach to Ruby installation, allowing multiple Ruby versions to coexist on the same system. This capability is invaluable for developers working on multiple projects with different Ruby version requirements.

RVM handles the complex task of compiling Ruby from source while managing environment variables, gem sets, and version switching. The tool integrates seamlessly with shell environments, automatically switching Ruby versions based on project-specific configuration files.

This method requires additional setup steps but provides unparalleled flexibility for Ruby development environments. RVM also simplifies the process of testing applications across multiple Ruby versions.

Method 3: rbenv Installation

rbenv offers an alternative approach to Ruby version management with a focus on simplicity and minimal shell integration. Unlike RVM, rbenv doesn’t override shell commands or modify the shell environment extensively, preferring a lightweight approach to version management.

The rbenv system uses shims to intercept Ruby-related commands and route them to the appropriate Ruby version. This approach provides predictable behavior and easier troubleshooting when version-related issues arise.

While rbenv requires manual installation of the ruby-build plugin for compiling Ruby versions, it offers excellent compatibility with various shell environments and deployment tools used in production environments.

Installing Ruby with RVM (Recommended Method)

RVM Setup and Configuration

The RVM installation process begins with importing the project’s GPG keys to verify the authenticity of downloaded files. This security measure protects against tampered installation scripts and ensures you’re installing legitimate software.

gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Download and execute the RVM installation script from the official source:

curl -sSL https://get.rvm.io | bash -s stable

After installation completes, reload your shell environment to activate RVM functionality:

source ~/.rvm/scripts/rvm

Verify that RVM installed correctly by checking the available commands:

rvm --version

Ruby Installation Process

With RVM properly configured, install the latest stable Ruby version. RVM automatically handles dependency installation and compilation:

rvm install ruby --latest

Set the newly installed Ruby version as your default:

rvm use ruby --default

Verify your Ruby installation by checking the version:

ruby --version

The installation process may take 10-15 minutes as RVM compiles Ruby from source code. During compilation, RVM automatically installs any missing dependencies and optimizes the build for your specific system architecture.

Node.js and Yarn Installation

Node.js Setup

Modern Rails applications require Node.js for the Asset Pipeline, which manages JavaScript and CSS preprocessing, minification, and bundling. Rocky Linux 10 provides Node.js through the AppStream repository with multiple version options.

Enable the Node.js module and install the latest LTS version:

sudo dnf module enable nodejs:18
sudo dnf install nodejs npm

Verify the Node.js installation:

node --version
npm --version

Yarn Package Manager

Yarn provides faster, more reliable JavaScript package management compared to npm alone. Rails applications benefit from Yarn’s advanced caching and dependency resolution capabilities.

Install Yarn globally using npm:

sudo npm install -g yarn

Verify Yarn installation:

yarn --version

Yarn integrates seamlessly with Rails’ Webpacker system, providing efficient management of JavaScript dependencies and modern frontend build processes.

Installing Ruby on Rails

Rails Installation Process

With Ruby, Node.js, and Yarn properly installed, proceed with Rails installation using RubyGems, Ruby’s package management system. Install the latest Rails version globally:

gem install rails

The installation process downloads Rails and all its dependencies, which may take several minutes depending on your internet connection. Rails includes numerous gems that provide framework functionality, from database abstraction to testing tools.

For production environments or specific project requirements, you might need to install a particular Rails version:

gem install rails -v 7.0.4

Rails Installation Verification

Verify your Rails installation by checking the version:

rails --version

Ensure all components work together by checking the complete Ruby on Rails stack:

ruby --version
rails --version
node --version
yarn --version

All commands should return version information without errors, indicating a successful installation of the complete Rails development stack.

Database Setup Options

SQLite Configuration (Default)

SQLite serves as Rails’ default database backend, providing a lightweight, file-based database perfect for development and small applications. SQLite requires no additional server setup or configuration, making it ideal for rapid prototyping and learning environments.

SQLite comes pre-configured with Rails installations and requires no additional setup steps. New Rails applications automatically use SQLite unless otherwise specified during creation.

While SQLite works excellently for development, consider upgrading to PostgreSQL or MySQL for production applications that require concurrent user access and advanced database features.

PostgreSQL Integration

For production-ready applications, PostgreSQL offers advanced features, excellent performance, and robust concurrent access capabilities. Install PostgreSQL on Rocky Linux 10:

sudo dnf install postgresql postgresql-server postgresql-contrib postgresql-devel

Initialize the PostgreSQL database:

sudo postgresql-setup --initdb

Start and enable PostgreSQL service:

sudo systemctl start postgresql
sudo systemctl enable postgresql

MySQL/MariaDB Setup

MariaDB provides an open-source MySQL-compatible database server with excellent Rails integration. Install MariaDB server and development libraries:

sudo dnf install mariadb-server mariadb-devel

Start and enable MariaDB service:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure the installation by running the security script:

sudo mysql_secure_installation

Creating and Testing Your First Rails Application

Creating a New Rails App

Generate your first Rails application to verify the complete installation. Navigate to your desired development directory and create a new Rails project:

rails new myapp

For PostgreSQL applications:

rails new myapp --database=postgresql

For MySQL applications:

rails new myapp --database=mysql

The rails new command creates a complete application structure with all necessary files, directories, and configurations. This process includes installing gem dependencies and setting up the development environment.

Starting the Rails Server

Navigate to your application directory and start the Rails development server:

cd myapp
rails server

The server starts on port 3000 by default. Open your web browser and navigate to http://localhost:3000 to view the Rails welcome page. This confirmation page indicates successful installation and proper configuration of your Rails development environment.

Install Ruby on Rails on Rocky Linux 10

The development server provides automatic code reloading, detailed error messages, and comprehensive logging to facilitate efficient application development.

Security and Production Considerations

Security Best Practices

Configure the Rocky Linux 10 firewall to allow appropriate access to your Rails applications. For development environments, temporarily allow access to port 3000:

sudo firewall-cmd --add-port=3000/tcp --zone=public

For production environments, configure proper SSL/TLS certificates and restrict access to necessary ports only. Implement regular security updates and monitor system logs for suspicious activity.

Production Deployment Preparation

Production Rails applications require additional considerations including environment-specific configurations, asset compilation, and process management. Install a production-ready web server like Nginx and application server like Puma or Passenger.

Configure environment variables for sensitive information like database credentials and API keys. Use tools like Capistrano for automated deployment and systemd for service management.

Troubleshooting Common Issues

Installation Problems

If Ruby compilation fails, ensure all development dependencies are installed correctly. Missing packages like gcc-c++ or openssl-devel frequently cause compilation errors.

For permission errors during gem installation, avoid using sudo with gem commands when using RVM. RVM manages Ruby installations in user space, eliminating the need for administrative privileges.

Resolve PATH issues by reloading your shell environment or manually sourcing RVM scripts. Incorrect PATH configuration prevents proper Ruby and Rails command recognition.

Runtime Issues

Database connection errors often result from incorrect configuration files or missing database servers. Verify database server status and connection credentials in config/database.yml.

Asset pipeline issues typically involve Node.js or Yarn configuration problems. Ensure both tools are properly installed and accessible from your Rails application directory.

Server startup problems frequently relate to port conflicts or missing dependencies. Check for running processes on port 3000 and verify all required gems are installed.

Performance Optimization and Best Practices

System Performance Tuning

Optimize Rocky Linux 10 for Rails development by adjusting system parameters for better performance. Increase file descriptor limits and configure swap space appropriately for memory-intensive Rails applications.

Monitor system resources using tools like htop, iotop, and vmstat to identify performance bottlenecks. Rails applications can be memory-intensive during development, especially with automatic code reloading enabled.

Development Environment Setup

Configure your preferred text editor or IDE with Rails-specific plugins and syntax highlighting. Popular choices include VS Code, RubyMine, and Vim with appropriate Ruby plugins.

Implement version control from the beginning of your projects using Git. Rails applications include comprehensive .gitignore files that exclude temporary files and sensitive configuration data.

Set up testing frameworks like RSpec or Minitest to ensure code quality and maintain application reliability throughout development.

Congratulations! You have successfully installed Ruby on Rails. Thanks for using this tutorial for installing the Ruby on Rails open-source web application framework on your Rocky Linux 10 system. For additional help or useful information, we recommend you check the official Ruby on Rails website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button