This site contains affiliate links — we may earn a commission if you sign up through them. Details

How to Host Ruby on Rails Applications: A Complete Server Setup Guide

How to Host Ruby on Rails Applications: A Complete Server Setup Guide

Ruby on Rails is a powerful web application framework, but hosting Rails applications requires different server setup and understanding compared to traditional PHP websites. This guide walks you through choosing a suitable VPS, installing the essential tools, configuring your web server, and preparing your environment for production deployment. Whether you are deploying your first Rails app or managing multiple services, understanding the hosting fundamentals will help you build a reliable and performant infrastructure.

How Ruby on Rails Differs from PHP Websites

PHP websites typically execute script files on disk, with the web server processing each file on demand. Ruby on Rails, by contrast, requires an application instance to run continuously on your server. Rails relies on a persistent application process (such as Puma or Unicorn) that maintains HTTP connections, and a web server like Nginx acts as a reverse proxy, forwarding requests to these processes. Additionally, Rails applications require extra preparation steps, including asset compilation and dependency management through a Gemfile, making the hosting setup more involved than a simple PHP installation.

Minimum VPS Requirements for Rails Applications

For small to medium Rails applications, a VPS with at least 2 CPU cores, 2 GB of RAM, and 20-30 GB of disk space is a reasonable starting point. However, the actual requirements depend on your application size and expected concurrent users. Applications with heavy processing or large user bases may need more RAM. Nowadays, SSD storage is the industry standard and delivers significantly faster read-write performance than traditional HDD. Additionally, consider choosing a provider that guarantees at least 99% uptime, as application reliability depends on consistent server availability.

Installing Ruby, Rails, and Bundler on a Fresh Server

Begin by preparing your Linux environment. Start with system updates (apt update && apt upgrade), then install dependencies needed to compile Ruby, such as build-essential, libssl-dev, libreadline-dev, and zlib1g-dev. The popular way to install Ruby is through rbenv, which lets you manage multiple Ruby versions on the same server. After Ruby is installed, add the Rails gem and Bundler, which handles dependency management for your Rails application. Using a version manager like rbenv is especially useful if you need to run multiple Ruby versions or upgrade Ruby without breaking existing applications.

Choosing an Application Server: Puma vs Unicorn

The application server is the process that maintains HTTP connections and responds to user requests. Puma is the most popular choice today because it handles concurrency efficiently through threading, allowing it to manage multiple requests on a single process. This makes Puma more resource-efficient in memory-constrained environments. Unicorn is an older server that uses separate processes for each request; while it still works, Puma's superior performance and lower resource footprint make it the recommended choice for new Rails applications. Puma also supports features like hot restarts and built-in SSL termination, providing more flexibility for modern deployment scenarios.

Setting Up Nginx as a Reverse Proxy for Rails

Nginx is a lightweight, fast web server that serves perfectly as a reverse proxy for Rails applications. It sits in front of your Puma server, accepting requests from the internet and forwarding them to your application processes. To configure Nginx, you create a configuration file that specifies the location of your Puma server (usually localhost:3000 or localhost:8080). Nginx also handles caching of static files, compresses responses to reduce bandwidth usage, and normalizes URLs. This separation between Nginx and Puma allows you to restart your application without bringing down the web server, and makes your infrastructure more flexible and secure.

RecommendedAsiaGB.com — Web Hosting & VPS we recommend. Servers in Thailand & Singapore, SSD storage, DirectAdmin control panel, 24/7 Thai-language support, 99% uptime.

Based in Thailand, ideal for Thai websites and businesses.

Visit AsiaGB →

Database Setup for Rails: PostgreSQL vs MySQL

The database is central to storing your application data. Rails works seamlessly with both PostgreSQL and MySQL. PostgreSQL offers advanced features such as native JSON support, full-text search, and array data types, making it excellent for applications needing sophisticated querying and data processing. MySQL, particularly its open-source fork MariaDB, is lightweight and fast, suitable for smaller applications where advanced features are not critical. Modern Rails applications typically default to PostgreSQL due to its rich feature set and excellent Rails integration. Whichever you choose, install the appropriate Ruby database gem (pg for PostgreSQL, mysql2 for MySQL), configure your database.yml file, and set up secure database credentials on your server.

Asset Pipeline: Precompilation and Production Serving

The Asset Pipeline is a Rails feature that compiles and minifies JavaScript, CSS, and images for production deployment. While development environments often serve uncompressed assets, production requires running rake assets:precompile to generate minified, fingerprinted files optimized for caching. These compiled assets are stored in public/assets and should be served directly by Nginx for maximum performance, bypassing the Rails application server. Fingerprinting ensures that when you update an asset, clients fetch the new version rather than serving a cached outdated file. This approach greatly reduces bandwidth and improves page load times.

Background Jobs: Sidekiq and Hosting Considerations

Background jobs are essential for applications that need to handle long-running tasks, such as sending emails, generating reports, or processing images. Sidekiq is a popular job processing library for Rails that uses Redis to queue and manage tasks. Instead of making users wait for these operations to complete, Sidekiq lets you queue the job in Redis and have separate worker processes handle it in the background. To host a Rails app using Sidekiq, you must install and run Redis and configure Sidekiq workers as separate system processes, typically managed by systemd or supervisor. Properly monitoring Sidekiq ensures that jobs complete successfully and that your background processes do not consume excessive resources.

Deployment Approaches: Capistrano, Docker, and CI/CD

Deployment is the process of moving your code from development to production servers. Capistrano is a traditional deployment tool that scripts the release process, automating tasks like pulling the latest code, installing gems, running migrations, and restarting the application server. Docker offers an alternative: deploying containerized versions of your application with all dependencies and runtime versions bundled together, ensuring consistency across environments. Modern teams also use CI/CD pipelines (such as GitHub Actions or GitLab CI) to automate testing and deployment whenever code is pushed to your repository. Choosing a deployment strategy depends on your application complexity, team size, and infrastructure preferences. Each approach has trade-offs between simplicity, flexibility, and operational overhead.

Frequently Asked Questions

Can Ruby on Rails applications run on shared hosting?

Generally, no. Rails applications require a persistent application process running at all times, which shared hosting platforms (typically designed for PHP) cannot provide. Rails requires either a VPS or dedicated server where you have full control to install Ruby, Bundler, and necessary tools. Some hosting providers offer specialized Rails hosting, but these come at a higher cost than basic shared hosting.

How much RAM does a typical medium-sized Rails app need?

Memory usage depends on your application's size and complexity. Each Puma process typically consumes 100-300 MB of RAM. If you run 4 Puma workers, expect around 400-1,200 MB just for the application. Add overhead for Nginx, Redis, your database, and the operating system, and you can see why 4 GB of RAM or more is recommended for production Rails applications. Larger applications may require 8 GB or more.

What is the difference between Puma and Unicorn?

The key difference is that Puma uses threads (multiple threads within a single process) while Unicorn uses multiple separate processes (each single-threaded). This makes Puma more memory-efficient. Puma is also more modern, actively maintained, and well-integrated with current Rails versions. Unless you have a specific reason to use Unicorn, Puma is the better choice for new Rails applications.

How do I safely deploy updates to a live Rails application?

The safest approach is using zero-downtime deployment techniques, such as rolling deployments supported by Capistrano. A proper deployment process should run database migrations first, gracefully close existing connections, and start new application processes. Automated testing via CI/CD pipelines catches issues before they reach production. It is also wise to keep database backups and have a rollback plan in case something goes wrong.

Which operating system works best for hosting Rails applications?

Linux, particularly distributions like Ubuntu, Debian, or CentOS, is the standard choice for hosting Ruby on Rails. Linux is cost-effective, stable, well-documented, and has a large community of Rails developers providing support and sharing knowledge. macOS is suitable for local development but not recommended for production servers. Windows is not a good fit for Rails hosting due to limited tooling and community support.