How to Install Ruby on Rails on Ubuntu

The Ruby on Rails framework provides various toolkits that help improve web application development efficiency. It provides various code templates and libraries, allowing developers to easily add new functionalities without writing from scratch.

However, setting up Ruby on Rails can be challenging for new developers. Users must first prepare the hosting environment properly and install several dependencies using various commands.

In this article, we will explain how to install Ruby on Rails on a Virtual Private Server (VPS). We’ll also walk you through the steps to build a Rails application and provide best practices when using the framework.

What Is Ruby on Rails?

Ruby on Rails is a web application framework based on the Ruby programming language. It offers various toolkits, libraries, code templates, and components that help streamline development. This framework uses the popular Model-View-Controller (MVC) architecture, making it highly flexible and suitable for all web applications, including websites and CMS.

How to Install Ruby on Rails on Ubuntu

In this section, we will explain how to install Ruby on Rails on Ubuntu 23.04 Virtual Private Server. Before proceeding, make sure you have purchased a VPS hosting plan that runs the operating system.

1. Prepare Your Ubuntu Server

To prepare the Rails environment, connect to your VPS using an SSH client like PuTTY or Terminal. Hostinger users can use a browser terminal to access their servers and run Linux commands remotely through a web browser.

To simplify the preparation process, make sure your system is clean with minimal bloatware and junk files. Unnecessary software on your server can slow down performance and cause conflicts, affecting its functionality.

Hostinger VPS hosting users can choose which software to install. They may also opt for a plain operating system to create a minimal, easy-to-set-up hosting environment.

Hostinger users can find their server IP address and SSH login credentials via VPS Dashboard → Overview → SSH Access. Instead of root, we recommend switching to other superuser accounts to avoid accidental modifications that can damage your system.

SSH login credentials location in Hostinger's VPS dashboard

Once connected, update the Ubuntu repository to make sure you are installing the latest package versions using the following commands: sudo apt update and sudo apt upgrade

2. Install Ruby on Ubuntu

Ruby on Rails prerequisites include the Ruby programming language, code compiler, and JavaScript runtime. Depending on your application, it may also require other optional packages like redis or readline.

For this tutorial, we will show you how to install all the necessary software using APT.

To install Ruby, run: sudo apt install ruby-full -y

Check if the system has successfully installed Ruby using the following command: sudo ruby -v

Terminal returns the installed Ruby version

If the command line interface returns a “command not found” error, it means the package was not installed properly. If the terminal outputs the Ruby version number, you can continue installing other required packages.

You can install different software depending on your preference. For this tutorial, we will install the build-essential compiler package, Git version control, PostgreSQL database, SSL library, and zlib compression: sudo apt install -y build-essential git-core libssl-dev zlib1g-dev postgresql postgresql-server-dev -All

Verify whether these packages are installed correctly by checking their versions. For build-essentials, use the grep command: apt list –installed | grep build-required

The grep command in Terminal returns the installation status of the build-essential package

Then, run the following commands to install the Node.js JavaScript runtime and Yarn package manager to enable the asset pipeline: sudo apt install -y nodejs thread

We recommend using the latest version to ensure optimal compatibility, security, and functionality. If unsure, check the developer release notes pages.

3. Install Rails on Ubuntu

We will install Ruby on Rails using the RubyGems package manager. This is the official source of the framework, which ensures that you get the latest version and frequent updates.

This tool also facilitates installation, removal and management of ruby gems. It also lets you easily manage dependencies and Ruby libraries to simplify project administration.

RubyGem usually comes pre-installed with the Ruby programming language. Check if your system has this by querying version number:gem -v

You can also install it manually using APT by running the following command: sudo apt install Rubygems -y

Install other necessary development packages like Bundler dependency management system and RBNV version manager. Use the following commands: sudo Gem install bundler && sudo apt install rbenv -y

If you host multiple applications, you may need a different version of Ruby. Instead of setting them manually, define a default version that applies to your entire system using the ruby-build plugin and rbnv.

For example, here is an rbenv command that sets the default Ruby version as 2.2.3:rbenv global 2.2.3

Once the prerequisites are installed, run this gem command to start the Rails installation process: sudo gem install rails

Query the version to check if you installed Rails successfully or not.

Instead of running commands, installing Rails in a Hostinger VPS takes only several steps:

  1. Log in to the hPanel and click VPS on the top menu.
  2. Select your VPS plan.
  3. Go to the sidebar → OS & Panel Operating System.
  4. Under the Change Your Operating System window, click Applications.
  5. Select Ubuntu 22.04 64bit with Rails/OpenLiteSpeed.
  6. Click Reinstall.
The operating system installation menu in Hostinger's VPS dashboard

Warning! Reinstalling your VPS operating system will wipe all its data. Before proceeding, create a backup if you wish to preserve its files.

4. Set up a Development Environment

After preparing the hosting area, set up your Rails development environment. The steps differ depending on your operating system, but we will show you how to do it in Windows.

Pro Tip

The steps to set up an Ubuntu development environment for Ruby on Rails are similar to those for the hosting area.

Installing A Code Editor or IDE

You need a text editor or an integrated development environment (IDE) to write and debug the code of your Rails application. You can choose any software that you are familiar with.

If unsure, check out our best code editors article. We recommend choosing one with features like syntax highlighter and autocompletion to help simplify the development process and reduce human errors.

In this tutorial, we will use Visual Studio Code (VSCode). This free IDE offers various plugins that help improve development efficiency, such as VSCode RDBG Ruby Code Debugger.

Installing Ruby on Windows

The development area requires the same dependencies as the hosting server. Instead of using Linux-like commands, Windows users will have to manually obtain the installer package from the official RubyInstaller website. We recommend the latest version of Ruby with DevKit.

Double-click the executable file and complete the Ruby installation. This process will also configure the RubyGem package manager and the Webbricks web server. WEBrick is a Rails development server that allows you to host an application on your local machine for testing.

Installing Rails on Windows

The steps for Rails installation in Windows are the same as for other operating systems. Open a command prompt, powershell, or VSCode terminal as an administrator and run this gem command: gem install rails

This will install the web framework and its dependencies. To make sure the software is installed correctly, check the Rails version using the following command: rails -v

VSCode terminal returns the installed Rails version

Installing Git Version Control

Git lets you easily push code and files from your local machine to a live environment. While Hostinger VPS supports other methods like SFTP, they are less efficient.

Download the latest version from the official Git website and complete the installation. Open the Git Bash application from the Start menu and run the following command to check the version: git version

Then, set up a Git repository to host your project code and documentation. Choose a platform that best suits your needs and workflow. For example, popular options include GitHub and BitBucket.

Git Bash returns the installed Git version number

5. Create Your First Rails Application

To create a Rails application, open your VSCode terminal by pressing the Ctrl + ` shortcut. Navigate to your project directory using the cd command: cd D:\Project

Create new Rails project files and folders using the following command and replace rails_app with your application name: rails new rails_app

The Application folder contains several directories, each for different purposes. For example, the app/ path contains the main components of the application, while config/ contains configuration files. Check out the Rails Getting Started Guide to learn more about structure.

Navigate to the main folder of the application using the cd command and run the project using the following: rails server –bindings=

Enter localhost:3000 in your web browser. If the Rails welcome screen appears, you can start writing the application’s code and push files to your server using Git commands.

The Ruby on Rails application welcome screen

After moving the files into your VPS, connect to it via SSH. Navigate to the project folder and enter the same command to start the application:rails server –binding=

Visting vpsipaddress:3000 in your web browser should load the application. Press Ctrl + C in the command-line interface to stop the application. Run the same command to restart it.

Ruby on Rails Best Practices

This section will explore best practices for Ruby on Rails installation to help you streamline the process.

Use Version Management with Ruby Version Manager (RVM)

Hosting multiple applications with different Ruby versions on one server can lead to incompatibility issues. RVM solves this problem by allowing users to manage multiple Ruby installations using a command line interface.

It lets you install, manage, and switch between different versions with ease. RVM also allows users to manage isolated environments for Gem installations called gemsets.

Hostinger VPS lets users install RVM to set up a solid environment to host their applications. Apart from ensuring functionality, this command-line tool helps simplify development as users do not need to manage multiple servers.

Enhance Development With Essential Gems and Packages

In Rails, gems are additional packages to extend the functionality of the framework and simplify tasks. Users can install them using the Bundler gem dependency manager.

To do this, add your desired gem to your project’s gemfile by inserting the following new line:gem ‘gem_name’

Then, install the package by running the bundle command: bundle install gem_name

There are different gemstones with different purposes. For example, install Devise to set up user authentication on your application. In the meantime, use Paperclip or CarrierWave to enable file uploads.

Use Version Control with Git

In software development, a version control system allows developers to track project changes. In addition to providing a restore point for troubleshooting, it also enables continuous integration and deployment (CI/CD) to automate the process.

Git is a version control system that lets developers streamline their development tasks and improve collaboration. This enables non-linear workflow, allowing them to work together on a project rather than individually.

Developers can use simple Git commands to send files to a remote server and create a separate development branch, improving efficiency. Check out our Git tutorial to learn more about this tool.

Join the Ruby on Rails Community

Ruby is one of the most commonly used server-side programming languages, more popular than JavaScript. Due to its popularity, there is a large community of users behind the Rails framework.

This benefits users, especially beginners, as they can quickly find solutions when they encounter difficulties related to the framework. They can ask questions or search for answers on various online forums.

For example, Rails has an official forum with many active users. Additionally, developers can join non-official discussion boards from Rails course providers like GoRails or other popular platforms like Reddit.

Stay Updated

Installing the latest Ruby and Rails versions ensures that your application applies the latest security patches. Additionally, updates usually come with bug fixes and new software compatibility to improve the stability of your hosting environment.

Using Rails and the latest version of Ruby also ensures that you get ongoing support to simplify troubleshooting. To stay updated, subscribe to web development newsletters, participate in forums, and view release notes.

If you run multiple applications, use a tool like RVM to simplify the task. For example, you can use this command to list all available Ruby versions: rvm list


Ruby on Rails is a popular framework for developing web applications. It offers various libraries, templates, and toolkits that allow developers to add new functionality to their software without coding from scratch.

In this article, we have provided Ruby on Rails installation guide on Ubuntu:

  1. Prepare hosting environment. Connect to your remote VPS via SSH using a superuser account. Install the Ubuntu operating system and update the packages via APT.
  2. Install Ruby. Use APT to install the Ruby, RubyGems, and other dependencies. For example, configure PostgreSQL database, GCC compiler, and NodeJS.
  3. Install Rails. Download and install Ruby on Rails using RubyGems. In addition, install rbenv or RVM if you run multiple Ruby environments.
  4. Set up the development environment. Download a text editor or an IDE like VSCode. Then, set up Ruby and Rails via a command line interface like Command Prompt.
  5. Create and push your application. Run the rails new command in your IDE’s Terminal to start a project. Write your application code and push it using Git or an FTP client.

Install the latest version of Ruby and Rails to ensure optimal application performance and stability. To stay updated, check the release notes regularly and join a Rails community like a forum or subreddit.

To improve development efficiency, use the RVM version manager, additional gems, and the Git version control system. Hostinger VPS hosting environment supports all these tools to ensure an optimal web development experience.

FAQ: Install Ruby on Rails on Ubuntu

Here are the questions and answers about installing Ruby on Rails on Ubuntu, with corrections:

1. How to Download Ruby on Rails on Ubuntu?

While RubyGems is typically pre-configured with the Ruby installation on Ubuntu, it’s not strictly required to download Rails. You can directly install the Rails framework using the apt command:

sudo apt install ruby-rails

This command will automatically install Ruby, RubyGems, and Rails, eliminating the need for the gem install ruby command.

2. Which IDE Is Best for Ruby on Rails Ubuntu?

Both RubyMine and VSCode are excellent choices for Ruby on Rails development on Ubuntu. However, the “best” option depends on your individual preferences and budget.

  • RubyMine: Offers advanced features and tools specifically designed for Ruby on Rails development, but comes with a paid subscription.
  • VSCode: Free and open-source, highly customizable with a vast range of extensions, including extensions for Ruby on Rails development.

Ultimately, the best IDE is the one that best suits your needs and workflow.

3. Can I Host Ruby on Rails Applications on Hostinger’s VPS?

Yes, Hostinger’s VPS supports all software needed to develop and host Ruby on Rails applications. They provide:

  • A clean and configurable Ubuntu 22.04 environment
  • A one-click template for easy server setup with Rails pre-installed
  • Support for all necessary software, including Ruby, RubyGems, Rails, and a web server like Apache or Nginx

My name is Megha, A computer science student with a passion for digital marketing and SEO, enjoys helping beginners build impressive WordPress websites.

Leave a Comment