How to Ruby on Rails 7 on Ubuntu 24.04
Ruby on Rails 7 is a free web framework that lets you build websites quickly using the Ruby programming language. Setting it up on Ubuntu 24.04 involves installing Ruby version 3.2.1 or newer, a tool to manage different versions, and the Rails package itself.
You can follow this step-by-step setup guide to get everything running on your system so you can start building web apps right away.
Install Ruby using `apt install ruby3.2`, then install Rails with `gem install rails -N –version=’~> 7.0, < 8.0'`. Finally, configure your database and create a new Rails application using `rails new myapp -d mysql`.
Install Ruby
Preparing the environment requires installing Ruby beforehand. This guide covers setting up Ruby version 3.0.2 as the initial foundational step.
Run the command below to install Ruby.
sudo apt update
sudo apt install ruby3.2
Check the installed version by executing the command below.
Preparing Ruby and essential tools comes before installing Rails 7 on Ubuntu 24.04. The terminal executes commands to set up these dependencies. The ‘gem’ command then pulls down the Rails framework for building web applications.
Run the command below to install necessary packages that support Rails.
sudo apt install ruby-dev libmysqlclient-dev gcc make yarnpkg libxml2 libxml2-dev libxslt-dev libyaml-dev nodejs git
Use the 'gem' command (Ruby's package manager) to install Rails once those dependencies finish downloading.
sudo gem install bundler
sudo gem install nokogiri -- --use-system-libraries
sudo gem install rails -N --version='~> 7.0, < 8.0'
Verify the installation by running the command below to check the active version.
rails -v
Configure Rails app
Deploying a Rails app on Ubuntu 24.04 requires a database backend to store application records. MariaDB serves as a reliable option for this role. Terminal commands handle the installation and creation of a dedicated database for the application.
Storing application data requires a dedicated database management system.
Run the command below to install MariaDB, a popular database system.
sudo apt install mariadb-server
Create a blank database after MariaDB finishes installing.
Connect to the database server first.
sudo mariadb
Establish a blank database named [myapp].
CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Provision a new user and assign a password, such as [myuser] with 'mypassword'.
CREATE USER myuser@localhost IDENTIFIED BY 'type_your_password_here';
Grant this user full access to the database.
GRANT ALL ON myapp.* TO myuser@localhost WITH GRANT OPTION;
Save changes and exit the interface.
With MariaDB running, transition next to configuring the database adapter inside the Rails application. This configuration ensures that application functions can store and retrieve records reliably.
Connect the database client and generate a new application named [simpleapp].
sudo gem install mysql2 -- --with-mysql-config=/usr/bin/mysql_config
rails new simpleapp -d mysql
Navigate into the simpleapp folder and create a database configuration file.
cd simpleapp
nano config/database.yml
Populate the file with the configuration below, inserting the database username and password created earlier.
#
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 changes and close the editor.
Open the application configuration file next.
nano config/application.rb
Paste the content below into the file. The highlighted line defines a custom domain name, preventing the application from restricting access to 'localhost' or raw IP addresses.
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
Run the command below to build the application artifacts.
rails generate scaffold testapp name:string title:string body:text
rails db:migrate
Start the application server using the command below.
rails server --binding=0.0.0.0
Access the server via a web browser using the assigned IP address or hostname followed by port 3000.
http://srv1.example.com:3000

Test the running application.
http://srv1.example.com:3000/testapps/
Configuration is complete.
Conclusion:
Deploying Ruby on Rails 7 on Ubuntu 24.04 requires completing these core operations:
- 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.
A fully functional Ruby on Rails 7 environment emerges upon completing these steps. Development and testing of web applications on Ubuntu 24.04 can now proceed locally.
Was this guide helpful?
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.
No comments yet — be the first to share your thoughts!