Installing Ruby on Rails on Ubuntu 22.04

The guide describes how to install Ruby on Rails on Ubuntu 22.04.
We will do everything through the console in a few steps.

We add the repository key to the system:

We download the RPM installer

The command will automatically install the required packages and install the Ruby version 2.7.

After completing all the installation, load the RVM to the system with the following command.

Then update the RVM to the latest stable version and add the root user to the rvm group.

Then check the rvm version with the command below.

We move on to installing Ruby on Rails.

When the entire installation is complete, set Ruby 2.7.1 as the default version.

Now check the Ruby version with the command below.

Installation of the necessary Nodejs and Yarn packages

Now add the Nodejs Nodesource repository.

Then add the GPG key and the Yarn package manager repository.

Then update all available packages on your system and install Nodejs and Yarn, using the apt command below.

After completing all the installation, check the Nodejs version with the following command.

We are updating GEM packages:

We install rails

In this tutorial, we will use PostgreSQL as the database for our Rails project. In this step, we will install the PostgreSQL database server provided by the official ubuntu repository.

Install the PostgreSQL database server on Ubuntu 20.04, using the apt command below.

We run in the system:

Then log in to the PostgreSQL shell and create a new role "user_dev" with the password "password" and permissions "createdb" and "login".

Now see all available users in PostgreSQL, using the following query.

By default, Ruby on Rails used SQLite as the default database. In this guide, we're going to start a new Rails project, using the PostgreSQL database.

Create a new project 'application’ with the default PostgreSQL database, using the following command 'rails'.

Now you will get the 'application' project directory, go to the project directory and edit the database configuration 'config / database.yml’ with the nano editor.

In the developer section, add the database configuration as below.

Save and close.

Then run the rails command below, to generate and migrate the database for our Rails project, and make sure, that there is no error.

After the installation is complete, start the default puma rails web server, using the command below.

"Application" will run on your public IP address with port "8080".

Now open your web browser and enter the server's IP address with port "8080" in the address bar.
You will see the first Ruby on Rails project.

In this step, we will create a new simple CRUD application using Ruby on Rails and a PostgreSQL database.

Generate a simple CRUD application with ruby ​​scaffold command, as below.

Then migrate your database with the following command.

make sure, that there is no error, and then restart the puma server.

Go back to the web browser and enter the server's IP address with port "8080", followed by the "/ posts" path.

Create a new post and enter a title and content.

As a result, a simple CRUD application with a PostgreSQL database was created using Rails.

Ultimately installing and configuring Ruby on Rails with PostgreSQL database on Ubuntu 20.04 has been successfully completed.

How useful this post was?

Click on the star, to evaluate it!

Average grade / 5. number of votes:

So far, no votes! Be the first to rate this post.