Ubuntu Linux

How to Ruby on Rails 7 on Ubuntu 24.04

Richard
Written by
Richard
Mar 5, 2025 Updated Jan 31, 2026 4 min read
How to Ruby on Rails 7 on Ubuntu 24.04

This article explains how to install Ruby on Rails version 7 on Ubuntu 24.04.

Ruby on Rails, commonly known as Rails, is a web application framework developed using the Ruby programming language. It streamlines the process of creating web applications by offering a structured approach to organizing code, handling database interactions, and managing the routing of web requests.

To install Ruby on Rails on Ubuntu, you must first install and set up Ruby, often using a version manager like RVM or rbenv.

After setting up Ruby, you can install Rails using the Gem package manager.

Install Ruby

To install Ruby on Rails, you first need to install Ruby. In this tutorial, we will be installing Ruby version 3.

Run the command below to install Ruby.

🐧Bash / Shell
sudo apt update
sudo apt install ruby3.2

After installing Ruby, run the command below to show the version installed.

💻Code
ruby -v

Install Rails

Now that Ruby is installed, let’s proceed with installing Rails. For this tutorial, we will be using Rails version 7.

Run the command below to install necessary packages to support Rails.

🐧Bash / Shell
sudo apt install ruby-dev libmysqlclient-dev gcc make yarnpkg libxml2 libxml2-dev libxslt-dev libyaml-dev nodejs git

After installing the packages above, use gem to install Rails.

🐧Bash / Shell
sudo gem install bundler
sudo gem install nokogiri -- --use-system-libraries
sudo gem install rails -N --version='~> 7.0, < 8.0'

After Rails is installed, run the command below to show the version installed.

💻Code
rails -v

Configure Rails app

After installing Ruby and Rails, set up your environment to begin building your app.

In most cases, a database will be needed.

Run the command below to install MariaDB.

🐧Bash / Shell
sudo apt install mariadb-server

Once installed, create a blank database.

First, log on to the database server.

🐧Bash / Shell
sudo mariadb

Then, create a blank database called [myapp].

💻Code
CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Create a user called [myuser] with password.

💻Code
CREATE USER myuser@localhost IDENTIFIED BY 'type_your_password_here';

Then, grant the user full access to the database.

💻Code
GRANT ALL ON myapp.* TO myuser@localhost WITH GRANT OPTION;

Save changes and exit.

💻Code
FLUSH PRIVILEGES;
exit

Once you have set up your database, proceed to the next steps to configure it for your application.

Run the command below to connect your database. Then, create a simple application called [simpleapp].

🐧Bash / Shell
sudo gem install mysql2 -- --with-mysql-config=/usr/bin/mysql_config
rails new simpleapp -d mysql

Change into the simpleapp folder and create a database configuration file.

Command Prompt
cd simpleapp
nano config/database.yml

Copy the content below into the file. Enter the database user name and password created above.

💻Code
#
default: &default
adapter: mysql2
encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: myuser
password: type_password_here
socket: /var/run/mysqld/mysqld.sock

development:
<<: *default
database: myapp

Save and exit.

Next, open the application file.

💻Code
nano config/application.rb

Copy the content below into the file. The highlighted line allows you to specify a domain name. If you do not specify a domain name, the app can only be accessed using localhost or an IP address.

💻Code
require "rails/all"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Simpleapp
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails versio>
config.load_defaults 7.2

# add domain name if you want user accessing via domain otherwise, only localhost or IP address be used.
config.hosts << ".example.com"

#
.......
end
end

Finally, run the command below to create your application.

💻Code
rails generate scaffold testapp name:string title:string body:text
rails db:migrate

Start the app by running the command below.

💻Code
rails server --binding=0.0.0.0

Once the app runs, open your browser and browse the server IP address or hostname followed by port 3000.

💻Code
http://srv1.example.com:3000
Install Ruby on Rails Ubuntu


Test your app.

💻Code
http://srv1.example.com:3000/testapps/

That should do it!

Conclusion:

In summary, installing Ruby on Rails on Ubuntu 24.04 involves several key steps:

  • Installation of Ruby: Ensure you have Ruby version 3.2 installed as it’s essential for Rails.
  • Rails Installation: Use the Gem package manager to install Rails version 7.
  • Database Setup: Install MariaDB, create a database, and set up a user for your Rails application.
  • Application Configuration: Create a new Rails application, configure the database connections, and specify additional settings like domain name if needed.
  • Run Your Application: Start the Rails server and access your application via a web browser.

By following these steps, you will have a fully functional Rails environment ready for development!

Was this guide helpful?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

2469 articles → Twitter

📚 Related Tutorials

Setup PHP Timezone in Nginx on Ubuntu 24.04
Ubuntu Linux Setup PHP Timezone in Nginx on Ubuntu 24.04
How to Install Signal Desktop on Ubuntu 24.04
Ubuntu Linux How to Install Signal Desktop on Ubuntu 24.04
How to Install Discord on Ubuntu 24.04: Step-by-Step Guide
Ubuntu Linux How to Install Discord on Ubuntu 24.04: Step-by-Step Guide
How to Install Windows Subsystem for Linux (WSL) on Windows 11
Ubuntu Linux How to Install Windows Subsystem for Linux (WSL) on Windows 11

Leave a Reply

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