Website Vidya
DevelopmentStep-by-Step Guide

How to Install Ruby on Rails on Ubuntu 24.04

Learn how to install Ruby on Rails on Ubuntu 24.04 LTS. Step-by-step guide covering rbenv, Ruby 3.3, Node.js, Yarn, Rails 7, and Puma systemd service daemon.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Install Ruby on Rails on Ubuntu 24.04
AI Executive SummaryCORE CIS AI

6 min read

Learn how to install Ruby on Rails on Ubuntu 24.04 LTS. Step-by-step guide covering rbenv, Ruby 3.3, Node.js, Yarn, Rails 7, and Puma systemd service daemon.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Updating System Repositories and Installing Compiler Build Dependencies
  • Step 2: Installing rbenv and ruby-build Version Manager
Grounded in full engineering runbookCORE CIS Ai Engine

Ruby on Rails is a renowned open-source server-side web application framework written in the Ruby programming language. Operating under the philosophies of 'Convention over Configuration' (CoC) and 'Don't Repeat Yourself' (DRY), Rails provides software engineers with an extraordinarily productive framework for building modern, database-driven web applications, RESTful APIs, and real-time WebSocket applications via ActionCable.

Deploying a Ruby on Rails development or production stack on Ubuntu 24.04 LTS pairs an exceptionally stable Linux OS with modern Ruby 3.3 concurrency features like YJIT and Ractors. Learning how to install ruby on rails on ubuntu 24.04 enables developers and system administrators to configure isolated Ruby version environments, compile native C extensions cleanly, and manage production web processes with Puma and systemd.

In this comprehensive step-by-step tutorial, we demonstrate how to install Ruby on Rails on Ubuntu 24.04 LTS (Noble Numbat). We cover installing C/C++ compiler dependencies, deploying the rbenv version manager and ruby-build plugin, compiling modern Ruby, installing Node.js and Yarn for JavaScript asset pipelines, installing the Rails 7 gem, bootstrapping a test project, configuring the Puma web server, and setting up systemd service daemons.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A server or workstation running Ubuntu 24.04 LTS.
  • A non-root user account configured with administrative sudo privileges.
  • At least 2 GB of RAM (4 GB recommended for compiling native C gems and running asset pipelines).
  • Active Internet connectivity to download rbenv plugins, Ruby sources, and RubyGems.

Step 1: Updating System Repositories and Installing Compiler Build Dependencies

Compiling Ruby from source via rbenv requires modern C/C++ compilers, development headers, compression utilities, and SSL libraries.

First, refresh your local APT repository index and upgrade installed packages.

Install foundational build utilities including build-essential, libssl-dev, libreadline-dev, zlib1g-dev, libyaml-dev, libsqlite3-dev, and git using APT.

Advertisement

These libraries ensure that Ruby native extensions (such as OpenSSL, Readline, and Psych YAML) compile cleanly without missing header errors.

# Update APT repository lists and upgrade packages
sudo apt update && sudo apt upgrade -y

# Install core build libraries and headers
sudo apt install -y git curl wget build-essential libssl-dev libreadline-dev zlib1g-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev libffi-dev

Step 2: Installing rbenv and ruby-build Version Manager

Using a version manager like rbenv is the industry standard for Ruby development. It allows you to install multiple isolated Ruby versions side-by-side, switch versions per project, and install gems without requiring root privileges.

Clone the official rbenv repository from GitHub into your user home directory at ~/.rbenv.

Configure your shell environment by adding rbenv shims and autocompletion to your ~/.bashrc profile.

Install the ruby-build plugin into ~/.rbenv/plugins/ruby-build to provide the rbenv install command.

Advertisement

Reload your bash shell configuration to activate rbenv.

# Clone rbenv repository
git clone https://github.com/rbenv/rbenv.git ~/.rbenv

# Configure shell environment
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc

# Install ruby-build plugin
mkdir -p ~/.rbenv/plugins
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

# Reload shell profile
source ~/.bashrc

# Verify rbenv installation
rbenv -v

Step 3: Compiling and Installing Modern Ruby via rbenv

With rbenv configured, compile and install the latest stable version of Ruby (such as Ruby 3.3.0).

Run rbenv install 3.3.0 to download the source code, configure compiler flags, and install Ruby into ~/.rbenv/versions/3.3.0.

Set this version as your global default Ruby interpreter using rbenv global 3.3.0.

Verify the installed Ruby version and ensure that the RubyGems package manager is operational.

# Install Ruby 3.3.0 (compilation takes 2-5 minutes)
rbenv install 3.3.0

# Set Ruby 3.3.0 as the global default
rbenv global 3.3.0

# Confirm active Ruby and gem versions
ruby -v
gem -v

Step 4: Configuring Gem Defaults and Installing Bundler

By default, RubyGems attempts to generate local ri and rdoc documentation for every installed gem, which slows down package installations significantly.

Configure gem defaults in ~/.gemrc to disable automatic documentation generation.

Install bundler, the dependency management tool that resolves gem version constraints in Rails applications.

Execute rbenv rehash to update rbenv shims for newly installed gem executables.

# Disable gem documentation generation
echo 'gem: --no-document' >> ~/.gemrc

# Install Bundler
gem install bundler

# Rehash rbenv shims
rbenv rehash

# Verify Bundler version
bundler -v

Step 5: Installing Node.js and Yarn for Asset Compilation

Modern Rails applications utilize JavaScript runtimes and package managers to compile frontend assets, manage Tailwind CSS or Bootstrap frameworks, and compile Stimulus controllers.

Install Node.js LTS using the official NodeSource repository.

Install the Yarn package manager globally via npm or official repositories.

Verify that both node and yarn are accessible on your system path.

# Add NodeSource repository for Node.js LTS
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

# Install Node.js
sudo apt install -y nodejs

# Install Yarn globally via npm
sudo npm install -g yarn

# Confirm Node and Yarn versions
node -v
yarn -v

Step 6: Installing Rails 7 via RubyGems

Now install the Ruby on Rails framework gem. Rails 7 introduces powerful modern frontend capabilities including Importmaps, Turbo, and Stimulus by default.

Execute gem install rails to download Rails and all its foundational gems (ActionPack, ActiveRecord, ActionView, ActiveJob, ActiveStorage).

Rehash rbenv shims using rbenv rehash so that the rails command-line executable is available in your shell.

Verify the installed Rails version.

# Install Ruby on Rails gem
gem install rails

# Update rbenv shims
rbenv rehash

# Confirm installed Rails version
rails -v

Step 7: Creating a Test Rails Application and Testing Puma Server

Bootstrap a new Rails application to confirm that database connections, gem dependencies, and asset pipelines are functional.

Run rails new testapp to generate a fresh application scaffolding.

Navigate into the project directory (cd testapp).

Launch the integrated Puma web server using bin/rails server --binding=0.0.0.0.

Open your web browser and navigate to http://your_domain_or_ip:3000 to view the 'Yay! You’re on Rails!' welcome banner.

# Create new test Rails application
rails new testapp
cd testapp

# Start Puma web server bound to all interfaces
bin/rails server --binding=0.0.0.0

# Server output confirms:
# * Puma starting in development on http://0.0.0.0:3000
# * Use Ctrl-C to stop

Step 8: Configuring UFW Firewall and Production systemd Daemon

If testing over a remote network, configure Ubuntu's Uncomplicated Firewall (UFW) to permit inbound traffic on development port 3000.

For production deployments, create a systemd service unit file at /etc/systemd/system/rails-app.service.

Configure the service to execute bundle exec puma -C config/puma.rb under your unprivileged user account.

Enable and start the service so that your Rails application launches automatically on system boot.

# Allow development port 3000 in UFW
sudo ufw allow 3000/tcp comment 'Allow Rails development port'
sudo ufw status numbered

# Create production systemd service template
sudo bash -c 'cat <<EOF > /etc/systemd/system/rails-app.service
[Unit]
Description=Puma Rails Application Server
After=network.target

[Service]
Type=simple
User='$USER'
WorkingDirectory='$HOME'/testapp
ExecStart='$HOME'/.rbenv/shims/bundle exec puma -C config/puma.rb
Restart=always
Environment=RAILS_ENV=production

[Install]
WantedBy=multi-user.target
EOF'

# Reload systemd
sudo systemctl daemon-reload

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

rbenv install fails with 'BUILD FAILED (Ubuntu 24.04 using ruby-build)'

Resolution: This indicates missing C headers. Ensure you installed all prerequisite development libraries: sudo apt install -y libssl-dev libreadline-dev zlib1g-dev libyaml-dev libsqlite3-dev. Check the build log in /tmp/ruby-build.*.log for exact compiler errors.

Command 'rails' not found after running 'gem install rails'

Resolution: rbenv requires rehashing after installing gems that provide command-line binaries. Run rbenv rehash. Ensure ~/.rbenv/bin and ~/.rbenv/shims are in your $PATH by verifying which rails.

Rails displays 'Blocked host: your_domain_or_ip'

Resolution: Rails development environment enforces DNS rebinding protection. Open config/environments/development.rb and add config.hosts << 'your_domain_or_ip', then restart the Rails server.

Security Best Practices and Hardening

Never run the Rails server or Puma daemon under the root user account; execute under an unprivileged standard user.

In production, store sensitive credentials (database passwords, API secrets, master key) using Rails encrypted credentials ('bin/rails credentials:edit') or environment variables.

Enforce HTTPS across all application routes by setting 'config.force_ssl = true' in 'config/environments/production.rb'.

Regularly run 'bundle audit' to scan your Gemfile.lock dependencies for known security vulnerabilities and CVE advisories.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

3 FAQs
Ubuntu's default apt install ruby package installs an older system-level Ruby version and forces gems to be installed as root. rbenv allows you to install multiple modern Ruby versions in your user home directory without root privileges.
Bootstrap your application with the PostgreSQL flag: rails new myapp -d postgresql. Ensure the libpq-dev package is installed on Ubuntu and configure your database credentials in config/database.yml.
Run gem install rails followed by rbenv rehash. In an existing project, update the rails version in your Gemfile and execute bundle update rails && bin/rails app:update.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Uncategorized•

How to Redirect HTTP to HTTPS in Nginx

If you’re running a website today and it’s still accessible over plain HTTP, you’re already behind. Modern browsers flag non-HTTPS sites as “Not Secure,” search engines favor encrypted websites, and users are far more cautious about where t...

RR
Rajesh Rai
Read More
Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout