There is a new version of this tutorial available for Debian 12 (Bookworm).

How to Install Ruby on Rails on Debian 11

Ruby on Rails is a free, open-source, and one of the most popular application stacks used for creating sites and web apps. It is written in Ruby programming language and follows the MVC concept. It comes with the Rails development framework that makes app development easier. There are many well-known applications based on Rails, such as Github, Airbnb, Soundcloud, etc.

In this tutorial, I will show you how to install Ruby on Rails on a Debian 11 system.

Prerequisites

  • A server running Ubuntu 20.04.
  • A root password is configured on the server.

Install RVM

RVM also called "Ruby Version Manager" is a command-line tool that allows you to easily install, manage, and work with multiple ruby environments from interpreters. It makes your job easier to manage multiple Ruby versions in your system.

First, install all the required dependencies using the following command:

apt-get install gnupg2 curl wget -y

Once all the dependencies are installed, import the GPG key wiht the following command:

gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -

Next, download and run the RVM installation script using the following command:

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

Once the RVM is installed, load the RVM system path using the following command:

source /usr/local/rvm/scripts/rvm

Next, verify the RVM version using the following command:

rvm version

You will get the following output:

rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

Install Ruby Using RVM

First, update the RVM to the latest version using the command below:

rvm get stable --autolibs=enable

Next, you will need to add the root user to the rvm group so that the root user can run the rvm command.

usermod -a -G rvm root

Next, install the latest version of Ruby using the following command:

rvm install ruby-3.0.2

Next, make the Ruby version the default version using the following command:

rvm --default use ruby-3.0.2

Next, verify the Ruby version with the following command:

ruby --version

You will get the following output:

ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]

Install Nodejs and Yarn

Next, you will need to install Nodejs in your system to process the JavaScript files. First, install the required dependencies using the following command:

apt-get install gcc g++ make -y

Next, add the Node source repository with the following command:

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

Next, run the following command to add the Yarn repository:

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

Finally, update the repository and install both Nodejs and Yarn packages with the following command:

apt-get update
apt-get install nodejs yarn -y

Once the installation is complete, verify the Nodejs version using the following command:

node --version

You will get the following output:

v14.18.1

You can also verify the Yarn version using the following command:

yarn --version

You should get the following output:

1.22.15

Upgrade Ruby Package Manager

Ruby also installed the RubyGems package in your system. It provides a gem command-line utility used to upgrade the RubyGems.

Run the following command to update the RubyGem to the latest version.

gem update --system

Now, verify the RubyGem version using the following command:

gem -v

You will get the following output:

3.2.29

It is also recommended to disable the installation of Ruby package documentation through the RubyGem configuration. You can disable it using the following command:

echo "gem: --no-document" >> ~/.gemrc

Install Ruby on Rails

You can now install the latest version of Ruby on Rails using the RubyGem command:

gem install rails -v 6.1.4

Once the installation is complete, verify the installed version of Rails using the following command:

rails -v

You will get the following output:

Rails 6.1.4

Create a Project with Ruby on Rails

At this point, Ruby on Rails is installed. Now, it's time to create a project using the Ruby on Rails.

First, create a new project using the Rails command as shown below:

rails new project

Next, change the directory to the project and verify all project files using the following command:

cd project
ls

You will get the following output:

app		 bin	 config.ru  Gemfile	  lib  node_modules  postcss.config.js	Rakefile   storage  tmp     yarn.lock
babel.config.js  config  db	    Gemfile.lock  log  package.json  public		README.md  test     vendor

Now, start the puma rails web server using the command below.

rails s -b 69.87.221.117 -p 8080

You should see the following 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.2-p107) ("Zawgyi")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 40403
* Listening on http://69.87.221.117:8080
Use Ctrl-C to stop

At this point, the Ruby on Rails project is up and listens on port '8080' You can now access it using the URL http://your-server-ip:8080. You should see the Rails default page:

Ruby on Rails

Conclusion

Congratulations! you have successfully installed Ruby on Rails on Debian 11. You can now start creating web apps using the Ruby on Rails framework.

Share this page:

0 Comment(s)