How To Set up Ruby on Rails on Debian 11

In this article, we want to teach you How To Set up Ruby on Rails on Debian 11.

Ruby on Rails is software code built on top of Ruby. Technically, it is defined as a package library called RubyGem, installed using the command line interface of the operating system.

Ruby on Rails is an open-source web development framework, which provides Ruby developers a time-saving alternative to developing code. It is a collection of code libraries, which offer a ready-made solution for repetitive tasks like developing tables, forms, or menus on the website.

How To Set up Ruby on Rails on Debian 11

Before you set up Ruby on Rails, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Debian 11.

Now follow the steps below to install Ruby on Rails on your server.

Install Ruby on Debian 11

First, you need to update your local package index with the following command:

sudo apt update

Then, install the dependencies on your server:

sudo apt install apt-transport-https ca-certificates gnupg2 curl

Next, you need to install the Ruby version manager (RVM) on Debian 11. Import the GPG key with the command below:

$ curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
Output
gpg: Total number processed: 1
gpg: imported: 1

Now install the RVM on your server with the command below:

curl -sSL https://get.rvm.io | bash -s stable --ruby

The command will automatically install the packages required, and install the latest stable Ruby version.

To start using the Ruby version manager on Debian 11, run the following command:

source /usr/local/rvm/scripts/rvm

At this point, you can list the available versions of Ruby with the command below:

rvm list known
Output
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.10]
[ruby-]2.5[.8]
[ruby-]2.6[.6]
[ruby-]2.7[.2]
[ruby-]3[.0.0]
...

Then, to install a specific version of Ruby you can use the command:

rvm install <version_number>

Verify your Ruby installation on Debian 11 by checking its version:

ruby -v
Output
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

Also, you can check the RVM version:

rvm -v
Output
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

If you want to set the installed version of Ruby as the system default, run the command below:

rvm use --default 3.0.0

Install Rails on Debian 11

At this point, that you have Ruby installed on Debian 11, you can use the command below to install Rails:

gem install rails
Output
35 gems installed

Verify your Rails installation by checking its version:

rails -v
Output
Rails 7.0.2.3

Install Node.js and Yarn on Debian 11

Rails need a Javascript runtime for application development. The simple and easiest way to install Node.js is to install them from the Debian default repository.

First, you need to add the Node.js repository on Debian 11 with the following command:

curl -sL https://deb.nodesource.com/setup_16.x | bash -

Then to install the Yarn package manager, run:

# curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
# echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Update your local package index:

sudo apt update

Now you can install Node.js and Yarn on Debian 11:

sudo apt install nodejs yarn

Verify your installations by checking the versions:

node -v
Output
v16.14.2
yarn -v
Output
1.22.18

Create a Rails Test Application on Debian 11

At this point, you can start your first Rails project. Here we named it testapp:

rails new testapp

Start your Rails application on Debian 11 with  the following command:

# cd testapp
# rails server -b 0.0.0.0
Output
=> Booting Puma
=> Rails 6.1.4.1 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.5.2 (ruby 3.0.0-p0) ("Zawgyi")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 9473
* Listening on http://0.0.0.0:3000
Use Ctrl-C to stop

By now, the Rails application should be running on port 3000.

Now open your web browser and type your server IP address with port ‘3000’ on the address bar.

http://Your_Server_IP_Address:3000/

You will get the default index.html page of Ruby on Rails.

Conclusion

At this point, you learn to Set up Ruby on Rails on Debian 11.

Hope you enjoy it.

Also, you may find the following links useful

Install Ruby on Rails on AlmaLinux 9

Set up Ruby on Rails with rbenv on Ubuntu 22.04

How To Set up Ruby on Rails on Ubuntu 20.04

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!