Home How to install Rails: A full-stack framework
Post
Cancel

How to install Rails: A full-stack framework

In this post I will show how to install RoR aka Ruby on Rails a full-stack framework. RoR is a framework that was built to deliver extremely fast web applications by using the concept of convention over configuration.

Requirements

First we need an operating system in this case we gonna use Debian 10, this installation tutorial is considering only the use of the terminal and the minimal system without a graphical interface, which can be used in a virtual machine or directly in the operating system installed in hardware, in addition, we need ruby ​​already installed on the machine, in this post we will use ruby ​​3.0.6.

Steps

  1. System update
  2. RoR installation
  3. SQLite installation
  4. NodeJS installation and Yarn (Not required in Rails 7.0 or greater)
  5. Creating a new application
  6. Usage examples
  7. Conclusion

System update

First we need to update our system packages:

1
sudo apt update -y

Optional: we can upgrade the packages.

1
sudo apt upgrade -y

RoR installation

To install RoR we just need to run a simple command:

1
gem install rails

If you want to install a specific version of rails run this command.

1
gem install rails -v 6.1.7.4

After installation is complete you can check if rails is installed by running the command:

1
rails -v

The output of the command should look something like this.

1
Rails 6.1.7.4

Or

1
gem list | grep rails

The output of the command should look something like this.

1
2
3
4
rails (6.1.7.4)
rails-dom-testing (2.2.0)
rails-html-sanitizer (1.6.0)
sprockets-rails (3.4.2)

SQLite application

To install SQLite we just need to run a simple command:

1
sudo apt install sqlite3

NodeJS installation and Yarn (Not required in Rails 7.0 or greater)

To install NodeJS we gonna use the Fast Node Manager, to intall run the command:

1
curl -fsSL https://fnm.vercel.app/install | bash

After that we have to put the fnm in the PATH of the system:

1
export PATH="/home/debian10/.local/share/fnm:$PATH"

Now we can see the fnm version with this command:

1
fnm --version

Now we need to specify the file that will contain the version of NodeJS that we want to install on our machine for RoR to work correctly:

1
echo "18.17.1" > .node-version

Now we can install the NodeJS version needed for RoR to work properly:

1
fnm install

You can check NodeJS version with this command:

1
node -v

Finally we need to install Yarn for this we will use NPM which is Node’s package manager and is already installed with it:

1
npm install --global yarn

Creating a new application

To create a new application basically we need to run the following command:

1
rails new myapp

After the completion of the command, a folder will be created with all the files necessary for the application to work.

We can launch the application by running the following command:

1
rails s

Now the application is running and you can view it by accessing it via browser at the address: localhost:3000

Usage examples

If you want to create an application that runs on a PostgreSQL database you can create a new application by running the following command:

1
rails new myapp --database=postgresql

You first need to have the pg gem installed in the gemset, it needs some operating system packages to be installed.

If you want to create an application that runs in API style you can create a new application by running the following command:

1
rails new myapp --api

If you want to create an application that runs in API style and runs with PostgreSQL you can create a new application by running the following command:

1
rails new myapp --api --database=postgresql

Conclusion

RoR is a very versatile framework that is still used in several startups due to its ability to generate concept web applications in a very affordable time, I have been working with RoR since version 3 and knowing that today it is in version 7 is quite gratifying.

I hope you like it, if you want and can you can share this text, I will be posting new content daily, favorite this blog to have access to new knowledge. Thanks to everyone who read this post.

This post is licensed under CC BY 4.0 by the author.