How to Ruby on Rails 7 on Ubuntu 24.04
Installing Ruby on Rails 7 on Ubuntu 24.04 means getting Ruby ready and then adding the Rails software.
Ruby on Rails, often called Rails, is a free tool that helps people build websites and web apps. It uses the Ruby programming language.
Rails makes web building faster by giving you ready-made ways to handle things like databases and web page addresses. For Rails 7, you’ll want to use Ruby version 3.2.1 or newer.
First, you install a specific Ruby version using a tool like rbenv. Then, you add the Rails software itself using RubyGems, which is like a store for Ruby tools.
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
Before installing Rails, you need to install Ruby. This tutorial guides you through installing Ruby version 3.0.2, the current stable release. It’s the first step before you can install the Rails framework.
Run the command below to install Ruby.
sudo apt update
sudo apt install ruby3.2
After installing Ruby, run the command below to see the version you’ve installed.
To install Rails 7 on Ubuntu 24.04, you first prepare Ruby and essential tools. Your computer’s command line will run a command that installs these tools. Then, you use the ‘gem’ command to install Rails, the software you use to build web apps.
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
Once those are installed, use the ‘gem’ command (Ruby’s package manager) to install Rails.
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 see the version you’ve installed.
rails -v
Configure Rails app
Setting up your Rails app on Ubuntu 24.04 usually involves adding a database to store your app’s information. MariaDB is a popular choice for this. You’ll install MariaDB using a command in your terminal and then create a new, empty database specifically for your Rails application.
You’ll likely need a database to store your application’s data.
Run the command below to install MariaDB, a popular database system.
sudo apt install mariadb-server
Once MariaDB is installed, create a blank database.
First, connect to the database server.
sudo mariadb
Then, create a blank database, for example, named [myapp].
CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Next, create a user with a chosen password, like [myuser] with ‘mypassword’.
CREATE USER myuser@localhost IDENTIFIED BY 'type_your_password_here';
Finally, grant this user full access to the database.
GRANT ALL ON myapp.* TO myuser@localhost WITH GRANT OPTION;
Save your changes and exit.
Once the initial database setup is complete, you can configure your PostgreSQL database for your Ruby on Rails 7 application. This configuration ensures that your application can correctly store and retrieve data, which is essential for all application functions.
Run the command below to connect your database. Then, create a simple application called [simpleapp].
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.
cd simpleapp
nano config/database.yml
#
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.
nano config/application.rb
Copy the content below into the file. The highlighted line lets you specify a domain name. Without a domain name, the app will only be accessible via ‘localhost’ or an IP address.
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.
rails generate scaffold testapp name:string title:string body:text
rails db:migrate
Start the app by running the command below.
rails server --binding=0.0.0.0
Once the app runs, open your browser and navigate to the server IP address or hostname followed by port 3000.
http://srv1.example.com:3000

Test your app.
http://srv1.example.com:3000/testapps/
That should do it!
Conclusion:
So, to recap, installing Ruby on Rails 7 on Ubuntu 24.04 involves these main 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.
You will have a fully functional Ruby on Rails 7 environment ready for development after following these steps. This environment allows you to write and test Ruby on Rails 7 web applications on Ubuntu 24.04.
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!