AlmaLinuxRHEL Based

How To Install Ruby on Rails on AlmaLinux 10

Install Ruby on Rails on AlmaLinux 10

Ruby on Rails remains one of the most powerful and elegant web application frameworks available today. When combined with AlmaLinux 10’s enterprise-grade stability and security features, it creates an ideal environment for developing robust web applications. This comprehensive guide walks you through every step of installing Ruby on Rails on AlmaLinux 10, from initial system preparation to launching your first application.

AlmaLinux 10 offers exceptional compatibility with Ruby development tools while maintaining the reliability that enterprise environments demand. Whether you’re a system administrator setting up a production server or a developer creating a local development environment, this tutorial provides multiple installation methods to suit your specific needs.

The installation process involves several critical components: preparing your system with essential development tools, choosing the optimal Ruby installation method, configuring databases, and implementing security best practices. Each method presented here has been tested extensively and includes troubleshooting guidance for common issues you might encounter.

Table of Contents

Prerequisites and System Requirements

System Requirements

Before beginning the Ruby on Rails installation on AlmaLinux 10, ensure your system meets the minimum hardware requirements. For development environments, allocate at least 2GB of RAM and 20GB of available disk space. Production environments benefit from 4GB or more RAM and SSD storage for optimal performance.

Your AlmaLinux 10 system should have a stable internet connection for downloading packages and dependencies. Network connectivity is essential throughout the installation process, as you’ll be accessing multiple repositories and downloading significant amounts of data.

Verify your AlmaLinux version using the following command:

cat /etc/os-release

User Permissions and Security

Administrative privileges are required for system-level installations and configurations. While you can perform many tasks with sudo access, some administrators prefer creating dedicated user accounts for Ruby development work.

Create a dedicated user account for Rails development:

sudo useradd -m -s /bin/bash railsdev
sudo usermod -aG wheel railsdev
sudo passwd railsdev

This approach enhances security by isolating development activities from system-critical operations. The wheel group membership provides sudo access when needed, while maintaining separation of concerns.

Essential Knowledge Base

Familiarity with Linux command-line operations significantly streamlines the installation process. Basic understanding of package management with DNF (Dandified YUM) helps troubleshoot dependency issues that may arise.

Web development concepts, while not strictly necessary, provide valuable context for understanding Rails’ architectural decisions and configuration requirements.

System Preparation and Updates

Comprehensive System Update

Begin by updating your AlmaLinux 10 system to ensure compatibility with the latest Ruby and Rails versions. A fresh system state prevents conflicts with outdated packages that might interfere with the installation process.

Execute a complete system update:

sudo dnf update -y
sudo dnf upgrade -y

Reboot your system if kernel updates were installed:

sudo reboot

After rebooting, verify your system is current:

sudo dnf check-update

Repository Configuration

AlmaLinux 10 includes most necessary packages in its default repositories. However, enabling the Extra Packages for Enterprise Linux (EPEL) repository provides access to additional development tools and Ruby ecosystem components.

Enable EPEL repository:

sudo dnf install -y epel-release
sudo dnf config-manager --set-enabled crb

Update repository metadata:

sudo dnf makecache

System Optimization

Clear package cache and remove unnecessary packages to optimize system performance:

sudo dnf autoremove -y
sudo dnf clean all

This cleanup process ensures optimal disk space utilization and reduces potential conflicts during the Ruby installation process.

Installing Development Tools and Dependencies

Essential Development Tools

Ruby compilation requires various development tools and libraries. AlmaLinux 10 provides these through the “Development Tools” group package, which includes GCC, make, and other essential compilation utilities.

Install development tools:

sudo dnf groupinstall -y "Development Tools"

Verify the installation by checking GCC version:

gcc --version

Ruby-Specific Dependencies

Ruby and its gems require specific libraries for optimal functionality. These dependencies must be installed before compiling Ruby from source or installing gems that require native extensions.

Install essential Ruby dependencies:

sudo dnf install -y openssl-devel readline-devel zlib-devel libffi-devel
sudo dnf install -y gdbm-devel ncurses-devel
sudo dnf install -y libyaml-devel sqlite-devel

These libraries provide:

  • OpenSSL: Cryptographic functionality and HTTPS support
  • Readline: Command-line editing capabilities
  • Zlib: Compression support for various gems
  • LibFFI: Foreign function interface for C extensions
  • GDBM: Database functionality for Rails applications
  • YAML: Configuration file parsing support

Database Development Libraries

Install database client libraries for popular database systems used with Rails applications:

sudo dnf install -y postgresql-devel mysql-devel sqlite-devel

JavaScript Runtime Environment

Rails’ asset pipeline requires a JavaScript runtime for compiling and minifying assets. Node.js provides the most comprehensive solution for modern Rails applications.

Install Node.js and npm:

sudo dnf install -y nodejs npm

Install Yarn package manager for enhanced dependency management:

sudo npm install -g yarn

Verify installations:

node --version
npm --version
yarn --version

Ruby Installation Methods Overview

Choosing the Optimal Installation Method

Three primary methods exist for installing Ruby on AlmaLinux 10, each with distinct advantages depending on your use case and requirements.

RVM (Ruby Version Manager) excels in development environments where multiple Ruby versions are necessary. It provides seamless version switching and isolated gemsets for different projects.

rbenv offers a lighter-weight alternative to RVM with a more minimalist approach to Ruby version management. It’s preferred by developers who want precise control over their Ruby environment without additional overhead.

Package Manager Installation provides the simplest approach, using AlmaLinux’s native DNF package manager. This method integrates well with system package management but offers limited version flexibility.

Version Considerations

Ruby 3.x provides significant performance improvements and new features that enhance Rails 7+ compatibility. Long-term support versions offer stability for production environments, while the latest versions provide cutting-edge features for development.

Consider your project requirements when selecting Ruby versions:

  • Production environments: Choose LTS versions for stability
  • Development environments: Latest stable versions for new features
  • Legacy applications: Match existing project requirements

Method 1: Installing Ruby via RVM

RVM Installation Process

RVM provides the most flexible Ruby installation method, supporting multiple Ruby versions and isolated gemsets. Begin by installing GPG keys for security verification.

Import RVM GPG keys:

gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Download and install RVM:

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

Load RVM into your current shell session:

source ~/.rvm/scripts/rvm

Add RVM to your shell profile for automatic loading:

echo 'source ~/.rvm/scripts/rvm' >> ~/.bashrc

Ruby Installation with RVM

List available Ruby versions:

rvm list known

Install the latest stable Ruby version:

rvm install ruby --default

For a specific version:

rvm install 3.3.0
rvm use 3.3.0 --default

RVM Configuration and Management

Create isolated gemsets for different projects:

rvm gemset create myproject
rvm use ruby-3.3.0@myproject

List installed Ruby versions:

rvm list

Update RVM itself:

rvm get stable

Verification and Testing

Verify Ruby installation:

ruby --version
gem --version

Test gem installation capabilities:

gem install bundler
bundler --version

Method 2: Installing Ruby via rbenv

rbenv Installation and Setup

rbenv provides a minimalist approach to Ruby version management with precise control over Ruby environments. Install rbenv from the official repository.

Clone rbenv repository:

git clone https://github.com/rbenv/rbenv.git ~/.rbenv

Add rbenv to your PATH:

echo 'export RBENV_ROOT="$HOME/.rbenv"' >> ~/.bashrc
echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Reload your shell configuration:

source ~/.bashrc

ruby-build Plugin Installation

Install ruby-build for compiling Ruby versions:

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

Ruby Installation Process

List available Ruby versions:

rbenv install --list

Install a specific Ruby version:

rbenv install 3.3.0

Set global Ruby version:

rbenv global 3.3.0

Set local Ruby version for specific projects:

rbenv local 3.3.0

rbenv Management

Refresh rbenv shims after installing gems:

rbenv rehash

List installed Ruby versions:

rbenv versions

Update rbenv and ruby-build:

cd ~/.rbenv && git pull
cd ~/.rbenv/plugins/ruby-build && git pull

Method 3: Installing Ruby via Package Manager

DNF Package Installation

AlmaLinux 10 repositories include Ruby packages that integrate seamlessly with system package management. This method provides simplicity at the cost of version flexibility.

Install Ruby and development packages:

sudo dnf install -y ruby ruby-devel rubygems

Install additional Ruby tools:

sudo dnf install -y rubygem-rake rubygem-bundler

Verification and Configuration

Check installed Ruby version:

ruby --version
gem --version

Update RubyGems system:

sudo gem update --system

Package Method Considerations

While convenient, package manager installation typically provides older Ruby versions compared to version managers. This approach works well for production environments prioritizing stability over cutting-edge features.

System-wide installation means all users share the same Ruby version, which simplifies administration but reduces flexibility for development environments requiring multiple Ruby versions.

Installing Ruby on Rails

Rails Installation Process

With Ruby properly installed, proceed to install the Ruby on Rails framework. Rails installation varies slightly depending on your Ruby installation method.

Install Rails globally:

gem install rails

For specific Rails versions:

gem install rails -v 7.0.4

Rails Configuration and Verification

Verify Rails installation:

rails --version

Check available Rails commands:

rails --help

Essential Rails Gems

Install commonly required gems for Rails development:

gem install bundler
gem install pg mysql2 sqlite3
gem install image_processing

These gems provide:

  • Bundler: Dependency management for Rails applications
  • Database adapters: PostgreSQL, MySQL, and SQLite connectivity
  • Image processing: ActiveStorage image transformations

Gem Configuration

Configure gem installation defaults:

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

This setting prevents automatic documentation generation, speeding up gem installations significantly.

Database Configuration

PostgreSQL Setup and Configuration

PostgreSQL provides robust features ideal for production Rails applications. Install and configure PostgreSQL server on AlmaLinux 10.

Install PostgreSQL:

sudo dnf install -y postgresql-server postgresql-contrib

Initialize PostgreSQL database:

sudo postgresql-setup --initdb
sudo systemctl enable postgresql
sudo systemctl start postgresql

Create Rails database user:

sudo -u postgres createuser -s railsuser
sudo -u postgres psql -c "ALTER USER railsuser PASSWORD 'securepassword';"

MySQL/MariaDB Configuration

MariaDB offers MySQL compatibility with enhanced performance features. Install and configure MariaDB for Rails applications.

Install MariaDB:

sudo dnf install -y mariadb-server mariadb
sudo systemctl enable mariadb
sudo systemctl start mariadb

Secure MariaDB installation:

sudo mysql_secure_installation

Create Rails database user:

sudo mysql -e "CREATE USER 'railsuser'@'localhost' IDENTIFIED BY 'securepassword';"
sudo mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'railsuser'@'localhost';"
sudo mysql -e "FLUSH PRIVILEGES;"

Database Connection Testing

Test database connectivity with Rails:

rails new testapp --database=postgresql
cd testapp
bundle exec rails db:create

Configure database credentials in config/database.yml:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: railsuser
  password: securepassword
  host: localhost

Web Server Configuration

Nginx Configuration for Rails

Nginx provides excellent performance for serving Rails applications in production environments. Configure Nginx as a reverse proxy for your Rails application.

Install Nginx:

sudo dnf install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx

Create Nginx configuration for Rails:

server {
    listen 80;
    server_name your_domain.com;
    root /path/to/your/rails/app/public;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Apache Configuration Alternative

Apache HTTP Server offers comprehensive features and extensive module support for Rails applications.

Install Apache:

sudo dnf install -y httpd mod_ssl
sudo systemctl enable httpd
sudo systemctl start httpd

Firewall Configuration

Configure firewalld to allow web traffic:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Creating Your First Rails Application

Application Generation

Generate a new Rails application with specific configuration options:

rails new myapp --database=postgresql --css=bootstrap
cd myapp

Database Setup and Migration

Configure database settings and create initial schema:

bundle exec rails db:create
bundle exec rails db:migrate

Testing Your Application

Start the Rails development server:

bundle exec rails server

Access your application at http://localhost:3000 to verify successful installation and configuration.

Install Ruby on Rails on AlmaLinux 10

Generate a simple controller for testing:

bundle exec rails generate controller Welcome index

Security Best Practices

System-Level Security

Implement comprehensive security measures for your AlmaLinux 10 Rails environment:

Install and configure fail2ban:

sudo dnf install -y fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban

Configure automatic security updates:

sudo dnf install -y dnf-automatic
sudo systemctl enable --now dnf-automatic.timer

Rails Application Security

Implement security best practices in your Rails applications:

# config/application.rb
config.force_ssl = true
config.ssl_options = { hsts: { subdomains: true } }

Use environment variables for sensitive configuration:

export DATABASE_PASSWORD="your_secure_password"
export SECRET_KEY_BASE="your_secret_key"

Database Security Hardening

Restrict database access and implement proper user permissions:

REVOKE ALL PRIVILEGES ON *.* FROM 'railsuser'@'localhost';
GRANT SELECT, INSERT, UPDATE, DELETE ON railsapp_production.* TO 'railsuser'@'localhost';

Performance Optimization

Ruby Performance Tuning

Optimize Ruby garbage collection for better performance:

export RUBY_GC_HEAP_INIT_SLOTS=1000000
export RUBY_GC_HEAP_FREE_SLOTS=500000
export RUBY_GC_HEAP_GROWTH_FACTOR=1.1

Rails Application Optimization

Configure Rails for optimal performance:

# config/environments/production.rb
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

Implement caching strategies:

# Enable Redis for caching
config.cache_store = :redis_cache_store, { url: "redis://localhost:6379/1" }

System-Level Performance

Tune system parameters for Rails applications:

echo 'vm.swappiness = 10' | sudo tee -a /etc/sysctl.conf
echo 'net.core.somaxconn = 1024' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Troubleshooting Common Issues

Ruby Installation Problems

Compilation Errors: Ensure all development dependencies are installed:

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

Permission Issues: Check file ownership and permissions:

ls -la ~/.rvm
sudo chown -R $USER:$USER ~/.rvm

Rails Application Issues

Database Connection Errors: Verify database service status:

sudo systemctl status postgresql
sudo systemctl status mariadb

Asset Pipeline Problems: Clear and recompile assets:

bundle exec rails assets:clean
bundle exec rails assets:precompile

Performance and Memory Issues

High Memory Usage: Monitor Rails processes:

ps aux | grep rails
top -p $(pgrep -f rails)

Slow Database Queries: Enable query logging:

# config/environments/development.rb
config.log_level = :debug

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 AlmaLinux OS 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