The cart is empty

Ruby on Rails, commonly referred to as Rails, is a popular web framework written in the Ruby programming language. It enables rapid application development thanks to a set of predefined conventions that reduce the amount of code developers need to write. Installing Rails on a server involves several steps, including preparing the system, installing Ruby, setting up Rails, and configuring the web server. This article provides a detailed guide on how to accomplish this.

Prerequisites

Before installing Ruby on Rails, ensure your server meets the following prerequisites:

  • Access to the server with superuser (root) privileges.
  • An installed and configured package management system (e.g., APT for Debian/Ubuntu or YUM for CentOS/RHEL).
  • An installed and functional web server (e.g., Apache or Nginx).

Step 1: Install Dependencies

First, update your package list and install the necessary dependencies. For Debian/Ubuntu-based systems, use:

 

sudo apt update
sudo apt install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn

For CentOS/RHEL-based systems:

sudo yum update
sudo yum install git curl gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison sqlite-devel

Step 2: Install Ruby Using rbenv

rbenv is a tool that allows for easy installation and management of multiple Ruby versions. Install rbenv and ruby-build:

 

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

Install Ruby:

rbenv install 3.0.0
rbenv global 3.0.0
ruby -v

Step 3: Install Bundler and Rails

After Ruby is installed, install Bundler, which is a package manager for Ruby:

 

gem install bundler

Then install Rails:

gem install rails -v 6.1.0
rbenv rehash
rails -v

Step 4: Configure the Web Server

To properly run Rails applications, it's necessary to set up a web server. Here's an example for Nginx using Phusion Passenger as the application server:

Install Passenger:

sudo apt install -y libnginx-mod-http-passenger
​

 or for CentOS/RHEL:

sudo yum install epel-release
sudo yum install nginx passenger passenger-devel

Configure Nginx and Passenger. Open the Nginx configuration file and set up the server block for your application.

Restart Nginx.

 

Installing Ruby on Rails on a server requires several steps, from preparing the system, through installing Ruby and Rails, to configuring the web server. Follow the provided guide for successful installation and configuration of Rails applications on your server.