Support Online
Skip to main content

Installing a Ruby on Rails Application: Step-by-Step Guide on Ubuntu 22.04

Ruby on Rails allows you to quickly develop web applications with its simple code structure and powerful MVC architecture. In this guide, you will install Rails, configure the database, perform CRUD operations and add simple authentication on the Ubuntu 22.04 operating system.

🚀 What Will You Learn in This Guide?

This guide lets you develop an application from scratch using Ruby on Rails on the GenixNode Virtual Server (V-Server). What you will learn step by step:

  1. Installing SQLite3 database
  2. Creating a new Rails project
  3. Creating the MVC structure with the scaffolding command
  4. Setting the application home page (root)
  5. Adding model validation
  6. Set up simple authentication

🧩 Step 1 — Setting Up the SQLite3 Database

Rails uses SQLite3 by default in the development environment. This is an ideal solution for simple projects.

sudo apt update
sudo apt install sqlite3 libsqlite3-dev

💬 These commands install SQLite and necessary development files.

To verify the installation:

sqlite3 --version

🧩 Stage 2 — Creating a New Rails Project

Now let's start a new application. For example, create a project named “balikapp”:

rails new balikapp
cd balikapp

💬 Rails creates the project directory with this command, sets the necessary files and Gemfile dependencies.

To test the server:

rails server

From the browser, go to http://localhost:3000. If you are using a GenixNode instance, open the port:

sudo ufw allow 3000
rails server --binding=your_server_ip

🧩 Stage 3 - Creating the Application Scaffold

Now we can quickly set up the CRUD structure. For example, let's create a model that manages fish information:

rails generate scaffold Balik isim:string bilgiler:text

💬 This command automatically creates model, controller, view and migration files.

Structures formed:

  • app/models/balik.rb
  • app/controllers/baliks_controller.rb
  • app/views/baliks/
  • db/migrate/...create_baliks.rb
  • config/routes.rbresources :baliks

Update the database:

rails db:migrate

🧩 Stage 4 — Setting the Root Route

To point the root directory to the fish list, open config/routes.rb and edit it like this:

Rails.application.routes.draw do
resources :baliks
root 'baliks#index'
end

💬 This setting redirects the app's homepage to the “Fish” list.

Start the server and test it at http://localhost:3000. You can add, edit or delete records with the “New Fish” button.


🧩 Step 5 - Adding Model Validations

To avoid empty or duplicate records, add the following to the app/models/balik.rb file:

class Balik < ApplicationRecord
validates :isim, presence: true, uniqueness: true
validates :bilgiler, presence: true
end

💬 The name field cannot be empty or duplicate, the information field is mandatory.

To test:

  • Try to add a second fish with the same name → it gives an error.
  • Leave blank → you will receive a warning message.

🧩 Stage 6 — Simple Authentication

Let's add basic HTTP authentication to the application. Add the following code to the app/controllers/application_controller.rb file:

class ApplicationController < ActionController::Base
http_basic_authenticate_with name: 'genixnode', password: 'gizlisifre', except: [:index, :show]
end

💬 This setting only requires authentication for actions other than “listing” and “viewing.”

Security note: Instead of using this method in production environments, professional gems such as Devise or bcrypt should be preferred.


🧩 Stage 7 — Testing

Start the server:

rails s
  1. Go to http://localhost:3000.
  2. Click the “New Fish” button.
  3. Enter username genixnode, password gizlisifre.
  4. Create a new record and check the list.

💬 Frequently Asked Questions (FAQ)

1️⃣ Why use SQLite? Ideal for simple installation and fast testing. PostgreSQL is recommended in a production environment.

2️⃣ What does the MVC structure do? Model manages the data, View manages the user interface, and Controller manages the interaction between these two.

3️⃣ Why use scaffolding? The rails generate scaffold command automatically creates CRUD files for a model.

4️⃣ Is Authentication safe? This method is for example only. Devise or JWT based systems should be used in real projects.

5️⃣ How to run Rails on GenixNode? You can create an Ubuntu 22.04 V-Server from the GenixNode panel and follow the steps in this guide.


🎯 Result

Congratulations! Using Ruby on Rails on Ubuntu 22.04:

  • You have installed the SQLite3 database,
  • You have created the application skeleton,
  • You added CRUD operations,
  • You have set up verification and basic authentication structures.

You are now ready to develop and publish your own Rails projects on the GenixNode platform.