How to Easily Install Ruby on Rails on Ubuntu VPS: A Step-by-Step Guide
Installing Ruby on Rails on a VPS can seem daunting, but with the right steps, it’s manageable for any developer.
What Is Ruby on Rails?
Ruby on Rails is a powerful web application framework based on the Ruby programming language. It provides various toolkits, libraries, and code templates that help streamline development. Utilizing the popular Model-View-Controller (MVC) architecture, Rails is highly flexible and suitable for a variety of web applications, including websites and content management systems (CMS).
How to Install Ruby on Rails on Ubuntu
In this section, we will explain how to install Ruby on Rails on an Ubuntu 22.04 virtual private server (VPS). Before proceeding, ensure you have purchased a VPS hosting plan running the Ubuntu operating system.
1. Prepare Your Ubuntu Server
To prepare the Rails environment, connect to your VPS using an SSH client like PuTTY or Terminal. If you are using Hostinger, you can access your server via the browser terminal and run Linux commands remotely from a web browser.
To simplify the preparation process, ensure your system is clean with minimal bloatware and junk files. Unnecessary software can slow down performance and create conflicts that affect functionality.
With Hostinger VPS hosting, users can choose which software to install, including opting for a plain operating system for a minimal setup. You can find your server’s IP address and SSH login credentials through the VPS Dashboard under Overview.
Once connected, update the Ubuntu repository to ensure you install the latest package versions using the following command:
sudo apt update && sudo apt upgrade
2. Install Ruby on Ubuntu
Ruby on Rails prerequisites include the Ruby programming language, a code compiler, and a JavaScript runtime. Depending on your application, you may also need optional packages like Redis or Readline.
For this tutorial, we will show you how to install all the required software using APT. To install Ruby, run:
sudo apt install ruby-full -y
Check whether Ruby has been installed successfully using the following command:
sudo ruby -v
If the command-line interface returns a “Command not found” error, the package wasn’t installed properly. If it outputs the Ruby version number, you can continue installing other essential packages.
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-essential, use the grep command:
apt list --installed | grep build-essential
Then, run the command to install the Node.js JavaScript runtime and Yarn package manager to enable the asset pipeline:
sudo apt install -y nodejs yarn
We recommend using the most recent version to ensure optimal compatibility, security, and functionality. If unsure, check the developer release note pages.
3. Install Rails on Ubuntu
With Hostinger’s Rails VPS hosting plans, you can set up Ubuntu with Rails/OpenLiteSpeed in one click. Each package also offers a browser terminal and Kodee – an AI Assistant.
We will install Ruby on Rails using the RubyGem package manager, which is the framework’s official source, ensuring you get the latest version and updates. This tool facilitates Ruby gems installation, removal, and management, allowing you to easily manage dependencies and Ruby libraries.
RubyGem usually comes pre-installed with the Ruby programming language. Check whether your system has it by querying the version number:
gem -v
You can also install it manually using APT by running:
sudo apt install rubygems -y
Next, install other essential development packages like the Bundler dependency management system and rbenv version manager:
sudo gem install bundler && sudo apt install rbenv -y
If you host multiple applications, you might require different Ruby versions. Instead of setting them up manually, define a default version that applies to your entire system using the ruby-build plugin and rbenv. For example, here’s a 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
Verify the installation by checking the Rails version:
rails -v
Instead of running commands, installing Rails in Hostinger VPS only takes several steps:
- Log in to the hPanel and click VPS on the top menu.
- Select your VPS plan.
- Go to the sidebar → OS & Panel → Operating System.
- Under the Change OS window, click Application.
- Select OpenLiteSpeed and Rails.
- Click Change OS.
Warning! Reinstalling your VPS operating system will wipe all data. Create a backup if you wish to preserve 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. Here’s how to do it in Windows, but the steps for Ubuntu are quite similar.
Installing a Code Editor or IDE
You will need a text editor or an integrated development environment (IDE) to write and debug your Rails application code. Choose any software you’re comfortable with.
If unsure, check our best code editors article. We recommend choosing one with features like syntax highlighting and auto-completion to simplify the development process and minimize errors. For this tutorial, we will use Visual Studio Code (VSCode), a free IDE that offers various plugins, such as the VSCode rdbg Ruby code debugger.
Installing Ruby on Windows
The development environment requires the same dependencies as the hosting server. Instead of using commands like on Linux, Windows users must obtain the installer package manually from the official RubyInstaller website. We recommend the latest version of Ruby with DevKit.
Double-click on the executable file and complete the Ruby installation. This process will also configure the RubyGem package manager and the WEBrick web server, which allows you to host an application locally for testing.
Installing Rails on Windows
The steps for Rails installation on Windows are similar to those on other operating systems. Open Command Prompt, PowerShell, or VSCode Terminal as an administrator and run:
gem install rails
This will set up the web framework and its dependencies. To ensure the software is installed correctly, check the Rails version using:
rails -v
Installing Git Version Control
Git lets you easily push code and files from your local machine to the 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. Popular options include GitHub and Bitbucket.
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 comprises several directories for different purposes. For instance, the app/ path contains the main components, while config/ houses the configuration files. Check the Rails start guide to learn more about the structure.
Navigate to the main application folder using the cd command and run the project:
rails server --binding=0.0.0.0
Enter localhost:3000 in your web browser. If the Rails welcome screen appears, you can start writing your application code and push files to your server using Git commands.
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=0.0.0.0
Visiting your VPS IP address: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 explores best practices for Ruby on Rails installation to help streamline your process.
Use Version Management with Ruby Version Manager (RVM)
Hosting multiple applications with different Ruby versions on one server may cause incompatibility issues. RVM addresses this by allowing users to manage multiple Ruby installations via a command line interface. It lets you easily install, manage, and switch between different versions.
RVM also allows users to create isolated environments for gem installations called gemsets. Hostinger VPS lets users install RVM for a solid hosting environment.
Enhance Development With Essential Gems and Packages
In Rails, gems are additional packages that extend functionality and simplify tasks. You can install them using the Bundler gem dependency manager. Add your desired gem to your project’s Gemfile:
gem 'gem_name'
Then, install the package by running:
bundle install gem_name
There are various gems for different purposes. For example, install Devise to set up user authentication, or use Paperclip or CarrierWave to enable file uploads.
Use Version Control with Git
A version control system allows developers to track project changes and provides a restore point for troubleshooting. It also enables continuous integration and deployment (CI/CD) to automate processes.
Git is a version control system that streamlines development tasks and improves collaboration. It enables a non-linear workflow, allowing developers to work concurrently on a project.
Developers can use simple Git commands to push files to a remote server and create isolated development branches, 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 popular server-side programming languages, even more popular than JavaScript. The Rails framework has a large community of users, which is beneficial for users, especially beginners, as they can quickly find solutions when encountering difficulties.
They can ask questions or search for answers on various online forums, including the official Rails forum and non-official discussion boards from Rails course providers like GoRails or platforms like Reddit.
Stay Updated
Installing the latest Ruby and Rails versions ensures your application applies the latest security patches. Updates often bring bug fixes and new software compatibility, improving hosting environment stability.
Using the new versions of Rails and Ruby also ensures you receive continuous support for troubleshooting. To stay updated, subscribe to web development newsletters, participate in forums, and check the release notes.
If you run multiple applications, use RVM to simplify management. For example, you can list all available Ruby versions with:
rvm list
Conclusion
Ruby on Rails is a popular framework for developing web applications, offering various libraries, templates, and toolkits that allow developers to add new functionality without coding from scratch.
In this article, we provided a comprehensive guide for installing Ruby on Rails on Ubuntu:
- Prepare the hosting environment by connecting to your remote VPS via SSH using a superuser account and updating the packages via APT.
- Install Ruby using APT, including RubyGems and other dependencies like PostgreSQL and NodeJS.
- Install Rails via RubyGems and consider using rbenv or RVM if you run multiple Ruby environments.
- Set up the development environment, downloading a text editor or IDE like VSCode, and configuring Ruby and Rails.
- Create and push your application by running the rails new command in your IDE’s Terminal, writing your application code, and pushing it using Git or an FTP client.
Install the latest version of Ruby and Rails to ensure optimal application performance and stability. Stay updated by regularly checking release notes and joining the Rails community through forums or subreddits. Improve development efficiency with RVM version management, additional gems, and Git version control. Hostinger VPS hosting supports all these tools for an optimal web development experience.
Install Ruby on Rails on Ubuntu FAQ
How to Download Ruby on Rails on Ubuntu?
To download Rails on Ubuntu, you need RubyGems, which is pre-configured when you install the Ruby programming language. After installing Ruby using Ubuntu’s APT manager, download the Rails framework via RubyGems using the gem install command.
Which IDE Is Best for Ruby on Rails on Ubuntu?
If you exclusively use the Ruby on Rails framework, we recommend RubyMine, which has various built-in tools for efficiently writing and debugging Ruby code. For a free IDE that supports various applications and frameworks, we recommend Microsoft VSCode.
Can I Host Ruby on Rails Applications on <a href=”https://hostinger.com?REFERRALCODE=1CRYPTO99″ rel=”sponsored noopener” target=”_blank”>Hostinger</a>’s VPS?
Yes, Hostinger VPS supports all software required for developing and hosting Ruby on Rails applications. We offer a clean hosting environment that users can easily configure to their needs. Additionally, we provide an Ubuntu 22.04 and Rails template, allowing users to prepare their server with a single click.
👉 Start your website with Hostinger – get fast, secure hosting here 👈
🔗 Read more from MinimaDesk:
- How to Disable xmlrpc.php in WordPress: A Step-by-Step Guide
- The Ultimate Guide to WP-Content: Access, Upload, and Hide Your WordPress Directory
- How Many WordPress Plugins Are Too Many? Optimize Your Site for Success
- Mastering WordPress: Solving Broken Permalinks Effortlessly
🎁 Download free premium WordPress tools from our Starter Tools page.