How to Install Ruby on Rails on Debian 11 Tutorial (Step by Step)

How to Install Ruby on Rails on Debian 11 Tutorial (Step by Step). Ruby on Rails is an open-source web application framework that’s used to build web applications. It is designed to make it easy for anyone to create robust, scalable and maintainable web applications in Ruby.

Worth mentioning that Ruby on Rails is a web application framework created by David Heinemeier Hansson (the creator of the Rails engine) and his team at 37signals. It was released in 2004, and it has since been used successfully to build many successful websites, including Basecamp, Twitter, Basecamp, GitHub, Shopify and Airbnb, as well as many others.

In this article, you will learn about how you can setup Ruby on Rails development environment on Debian 11.

What is Ruby on Rails

Firstly Ruby on Rails is an open source web application framework that includes everything needed to create database backed web applications according to the Model-View-Controller (MVC) paradigm.

The framework includes a full featured MVC (Model View Controller) framework. It also provides generators for creating models, controllers, and views.

Rail’s also provides a scaffolding system for quickly setting up new projects with support for internationalization, integration with the ActiveRecord ORM and Ajax library and an object relational mapper that maps Ruby objects to and from database tables. It also provides support for testing, logging support, and more.

The popularity of Ruby on Rails has also been attributed to its emphasis on convention over configuration and what is called “batteries included”, which means that there are many features built into Ruby that make it easy for developers to get started building web applications quickly.

These features include support for more than 20 database engines out of the box, support for authentication, support for templating, support for testing, and much more.

Besides Ruby on Rails is incredibly powerful, but it can be intimidating because of its robustness and power. This makes learning about Rails a little more difficult for beginners than with some other frameworks like Django or Laravel. However, with some practice, its immense potential in web development can be seen.

Features of Ruby on Rails

Ruby on Rails has several key features.

  • The model-view-controller architecture: Ruby on Rails utilizes the MVC architecture. The model is used to maintain the link between the object and the database, the view is used to generate data users for web applications, and the controller is used to combine the model and the view.
  • Active Records: Ruby on Rails introduces the active record framework. It is a sophisticated library that allows the developer to create interactive database queries.
  • Built in Testing: Ruby on Rails has a collection of tests that will run against your code. It will save you time and energy.
  • Ruby on Rails uses the metaprogramming approach.
  • Convention over configuration: In Ruby on Rails, a programmer can only declare the application’s unusual features.
  • Scaffolding: Ruby on Rails includes a scaffolding feature that allows the developer to describe how the application database operates.

Advantages of Ruby on Rails

  • Rails includes tools that enable us to provide more features in less time.
  • Almost anything we can think of has a third-party module (gem)/library for it.
  • Ruby code quality is substantially greater than PHP or NodeJS alternatives.
  • The Ruby community is very interested in test automation and testing.
  • Ruby on Rails has a big following in the community.
  • Productivity: Compared to other languages, Rails is extremely quick and productive.

Follow this post to learn how to install Ruby on Rails on Debian 11.

How to Install Ruby on Rails on Debian 11

Prerequisites

You will need:

  • Debian 11 system.
  • A user with root or sudo privileges.
  • A network connection.

Install Dependencies

Before you begin, you must install several dependencies on your server. You can install them all by running the following command:

				
					sudo apt-get install curl gnupg2 dirmngr git-core libcurl4-openssl-dev software-properties-common zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libffi-dev -y
				
			

You can move on to the next step after all of the requirements have been installed.

Install Node.js and Yarn

Basically on your server please install the Node.js server and the Yarn package. The most recent version of Node.js is not accessible by default in the Debian 11 default repository. As a result, you must add the Node source repository to APT using the following command:

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

After adding the repository, use the following command to install Node.js:

				
					sudo apt-get install nodejs -y
				
			

Please run the following command to check the Node.js version:

				
					node -v
				
			

You can see the Node.js version in the output:

				
					v16.16.0
				
			

Use the following command to add the Yarn repository:

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

Once the repository has been added, use the following command to update it and install the Yarn package:

				
					sudo apt-get update -y
sudo apt-get install yarn -y

				
			

Install Ruby on Debian

Ruby can be installed with several methods on Debian 11.

  • Install Ruby from the Debian 11 repository.
  • rbenv is used to install Ruby.
  • RVM is used to install Ruby.

Let’s take a look at each method one by one.

Ruby Installation using Debian 11 repository

Firstly we will update the Debian 11 repository to include all of the repository’s packages.

				
					sudo apt update
				
			

Then install Ruby using the command:

				
					 sudo apt install ruby-full -y
				
			

To validate the installation, you will use the version command to check the Ruby version.

				
					ruby --version

				
			

Output:

				
					ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu]
				
			

You can see that the Ruby version in the Debian repository is older than the current stable version of Ruby, which is Ruby 3.1.2.

Thus you can use the following methods to install the latest version of Ruby.

Install Ruby with rbenv

The rbenv utility makes it simple to install and manage different versions of Ruby. So get the rbenv source code from the Git repository: 

				
					sudo git clone https://github.com/rbenv/rbenv.git ~/.rbenv
				
			

Then, use the following command to export the rbenv path:

				
					sudo echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
sudo echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

				
			

After that, from the Git repository, get the ruby-build:

				
					sudo git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
				
			

Now use the following command to add the Ruby-build path:

				
					sudo echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

				
			

Here please use the following command to install the most recent version of Ruby:

				
					rbenv install 3.1.2
				
			

Output:

				
					Downloading ruby-3.1.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.2.tar.gz
Installing ruby-3.1.2…
Installed ruby-3.1.2 to /home/debian/.rbenv/versions/3.1.2
...
				
			

Set Ruby version 3.1.2 as the default version with the following command:

				
					 rbenv global 3.1.2
				
			

You can now use the following command to check the Ruby version:

				
					ruby -v
				
			

You should get the following results:

				
					ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
				
			

Run the following command to install the bundler package:

				
					gem install bundler
				
			

Install Ruby Using RVM

RVM (Ruby Version Manager) allows you to install and maintain Ruby versions independently by obtaining their dependencies automatically. First, use the following command to add the GPG key:

				
					gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
				
			

Download the RVM installation script from the project’s website with the following command.

				
					\curl -sSL https://get.rvm.io -o rvm.sh
				
			

Concurrently you can install the latest version of Ruby using the following command.

				
					rvm install 3.1.2
				
			

Run the following command to check the Ruby version:

				
					ruby -v
				
			

You should get the following results:

				
					ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]

				
			

Install Rails

To install the most recent version of Rails, use the gem command line program, as demonstrated below:

				
					sudo gem install rails
				
			

Run the following command to check the Rails version:

				
					sudo rails -v
				
			

Output:

				
					Rails 7.0.3.1
				
			

Create a Rails Application

Finally, you can build a simple Rails app to test the Ruby on Rails installation.

You can use the following command to construct a basic application called myapp:

				
					sudo rails new myapp
				
			

Using the following command, you may examine all files and folders produced by the preceding command:

				
					cd myapp
ls
				
			

Use the following command to launch the Rails application:

				
					sudo rails server -b 0.0.0.0
				
			

When you run the program, you will see the following output:

				
					=> Booting Puma
=> Rails 7.0.3.1 application starting in development 
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.6.4 (ruby 2.7.4-p191) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 17162
* Listening on http://0.0.0.0:3000
Use Ctrl-C to stop

				
			

Access Ruby on Rails app

Now, open your web browser and navigate to the URL http://your-server-ip:3000 to visit your Rails application.

That’s it for learning How to Install Ruby on Rails on Debian 11 Tutorial (Step by Step). 

How to Install Ruby on Rails on Debian 11 Conclusion

This article goes over multiple methods to install Ruby on Rails on the Debian 11 system. Now you can begin working on your own Rails application.

To conclude Ruby on Rails is an open source web application framework, used by programmers to build web applications with Ruby (and thus implement the Ruby programming language). The framework’s popularity has been attributed to its use of convention over configuration, its focus on programmer productivity, and its focus on a “batteries included” philosophy.

Ultimately Ruby on Rails is like a complete package for developing a web application. Explore our Ruby on Rails section to learn more.

Avatar for Sobia Arshad
Sobia Arshad

Information Security professional with 4+ years of experience. I am interested in learning about new technologies and loves working with all kinds of infrastructures.

5 2 votes
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x