Guide

How to deploy a Rails 8 app to a VPS

A $5–30 Ubuntu server runs a production Rails app comfortably: Puma, a job worker, Postgres, and automatic SSL. There are three ways to get there. Here's what each one involves, so you can pick the one that fits how much server work you want to own.

Every option ends with the same thing running on the server. A reverse proxy terminates SSL and forwards requests to Puma. A second process runs background jobs. Postgres stores your data, either on the same server or a managed service. What differs is who installs those pieces, who keeps them patched, and how a git push becomes a running release.

Three ways to deploy Rails to your own server

Kamal

Rails 8's default. rails new generates a Dockerfile, config/deploy.yml, and bin/kamal. Kamal builds an image, pushes it to a container registry, and swaps containers behind kamal-proxy with zero downtime. Free and open source. You own the Docker setup, the registry, database backups, and OS updates.

Build the server yourself

Install Ruby, Postgres, and Nginx or Caddy by hand, write systemd units for Puma and your worker, and deploy with Capistrano or a script. No Docker, nothing to pay for, and you learn exactly how it works. Every upgrade and security patch is yours, and a second server means doing it again.

Hatchbox

Hatchbox sets up the same stack on your server for you — Ruby, Postgres or MySQL, Redis, Caddy — and deploys on every push. No Dockerfile, no registry. $15 per server per month with unlimited apps. The server stays in your cloud account, with root access.

If you already know Docker and want everything in your repo, use Kamal. If you'd rather not run Docker or babysit servers, that's what Hatchbox is for. See Hatchbox vs Kamal for a detailed comparison.

Step 1: Pick a server

Use a current Ubuntu LTS release. For a typical Rails 8 app with Puma, a job worker, and Postgres on one machine, start with 2 vCPUs and 4GB of RAM. Smaller works for a side project. Larger makes sense when jobs keep the CPU busy all day or the database outgrows memory.

Hetzner's cost-optimized servers are the cheapest at that size. DigitalOcean, Vultr, Linode, and AWS Lightsail cost more but offer more regions and managed databases. Compare them on Rails hosting on Hetzner, DigitalOcean, and AWS.

Step 2: Get the app ready for production

These apply whichever way you deploy.

Secrets

Production needs RAILS_MASTER_KEY to read config/credentials.yml.enc. Keep config/master.key out of git and set the key as an environment variable on the server.

RAILS_MASTER_KEY=<contents of config/master.key>
DATABASE_URL=postgres://user:password@localhost/myapp_production

Postgres instead of SQLite

rails new defaults to SQLite, which works in production on a single server if you keep the database on a persistent disk and back it up. For more than one server, or if you're used to Postgres, add the pg gem and point config/database.yml at DATABASE_URL.

Health check

Rails 7.1 and later generate a /up route that returns 200 once the app boots. Kamal checks it before sending a new release traffic, and Hatchbox detects it and waits on it between web server restarts.

Step 3a: Deploy with Kamal

In config/deploy.yml, set your server's IP address, a container registry and its username (Docker Hub, GitHub Container Registry, and so on), and the proxy host for your domain. Put the registry password and RAILS_MASTER_KEY in .kamal/secrets. Then:

bin/kamal setup    # first deploy: installs Docker, boots kamal-proxy and the app
bin/kamal deploy   # every deploy after that

kamal-proxy gets a Let's Encrypt certificate when ssl: true is set in the proxy section. Run Postgres either as a Kamal accessory (a container on the server, with a mounted volume for its data) or as a managed database. Solid Queue can run inside Puma with SOLID_QUEUE_IN_PUMA, or as a separate job role that runs bin/jobs.

Kamal doesn't patch the host OS, set up a firewall, or back up the database. Plan for those separately.

Step 3b: Build the server by hand

The classic setup, in the order you'd build it:

  1. Create a deploy user with your SSH key, turn off password login, and allow only ports 22, 80, and 443 through ufw.
  2. Install build tools and a Ruby version manager (rbenv, asdf, or mise), then the Ruby version from .ruby-version.
  3. Install Postgres from apt, and create a database user and database for the app.
  4. Install Caddy or Nginx. Caddy gets and renews SSL certificates on its own. Nginx needs certbot.
  5. Write a systemd unit for Puma and another for bin/jobs or Sidekiq, so they start on boot and restart if they crash.
  6. Deploy with Capistrano or a script: pull the code, bundle install, assets:precompile, db:migrate, and restart Puma.
  7. Schedule database backups to storage off the server, and turn on unattended security upgrades.

It works, and there's nothing to pay for. The cost is time: a day or two to get it right the first time, plus a Ruby, Postgres, or Ubuntu upgrade every so often.

Step 3c: Deploy with Hatchbox

  1. Connect your cloud account (Hetzner, DigitalOcean, AWS, Linode, Vultr, OVHcloud), or add any Ubuntu LTS server over SSH.
  2. Create a server. Hatchbox installs Ruby, Caddy, and the database you choose, sets up a firewall, and keeps security updates on.
  3. Create an app from your GitHub, GitLab, or Bitbucket repository and attach a Postgres database. Hatchbox sets DATABASE_URL, plus the Solid Queue, Solid Cache, and Solid Cable database URLs when those gems are in your Gemfile.lock.
  4. Add RAILS_MASTER_KEY under environment variables and deploy.

Hatchbox detects Rails from your Gemfile, runs assets:precompile, runs db:migrate once per deploy, and starts Puma. It adds a bin/jobs process when it detects Solid Queue, and a Sidekiq process (with Redis) when it detects Sidekiq. Add a domain and Caddy issues the SSL certificate. See how a Rails deploy works.

Setting up Postgres, Sidekiq, and SSL on the server

Postgres

Install Postgres from apt, then create a user and a database owned by it. The app connects with a DATABASE_URL built from those.

sudo -u postgres createuser --pwprompt myapp
sudo -u postgres createdb -O myapp myapp_production
# DATABASE_URL=postgres://myapp:password@localhost/myapp_production

Rails 8's Solid Queue, Solid Cache, and Solid Cable each expect a database of their own in production. Create them the same way and set QUEUE_DATABASE_URL, CACHE_DATABASE_URL, and CABLE_DATABASE_URL, or point them at the main database in config/database.yml.

Sidekiq

Sidekiq needs Redis. Install redis-server from apt, set REDIS_URL=redis://localhost:6379/0, and run Sidekiq under systemd so it starts on boot and restarts after a crash. Adjust the paths for your Ruby version manager and deploy directory:

# /etc/systemd/system/myapp-sidekiq.service
[Unit]
Description=Sidekiq for myapp
After=network.target redis-server.service

[Service]
Type=simple
User=deploy
WorkingDirectory=/home/deploy/myapp/current
EnvironmentFile=/home/deploy/myapp/.env
ExecStart=/home/deploy/.rbenv/shims/bundle exec sidekiq -e production
Restart=always

[Install]
WantedBy=multi-user.target

Enable it with sudo systemctl enable --now myapp-sidekiq, and restart it after each deploy so it loads the new code. Solid Queue works the same way with bin/jobs in place of Sidekiq, and needs no Redis.

SSL

Point your domain's A record at the server first: Let's Encrypt only issues a certificate once the domain resolves to it. Caddy then gets and renews the certificate on its own with a two-line site block. With Nginx, run certbot and let it set up renewal. kamal-proxy does it when the proxy section has ssl: true.

example.com {
  reverse_proxy 127.0.0.1:3000
}

On Hatchbox, these are dashboard steps: attach a Postgres database and Hatchbox sets DATABASE_URL and creates the Solid databases, attach a Redis database for Sidekiq, and add a domain for SSL.

Before you go live

  • Backups that leave the server. A nightly pg_dump to S3-compatible storage, and one restore you've actually tested.
  • Error tracking. Honeybadger, AppSignal, Sentry, or similar.
  • Migrations that don't break the running release. During a zero-downtime deploy, old and new code run against the same database for a moment.
  • OS updates. Unattended security upgrades, and a plan for reboots when the kernel changes.
  • A second server, later. When jobs start slowing down web requests, move the worker to its own server before buying a bigger one.

Deploying Rails to a VPS: questions

Still stuck? Ask us directly — a real person who has deployed a lot of Rails apps to VPSs will answer.

What's the best way to deploy Rails 8 to production?

For most apps, a single Ubuntu server running Puma, a Solid Queue worker, and Postgres, with automatic SSL. Kamal is the Rails default and free if you're comfortable with Docker and running the server yourself. Hatchbox sets up and maintains the same stack without Docker for $15 per server per month. A platform like Render or Heroku costs more but means no servers at all.

How much RAM does a Rails app need on a VPS?

A typical Rails 8 app with Puma, one job worker, and Postgres on the same server runs well with 4GB. 2GB works for a small app with low traffic. Add memory when you run several apps on one server or the database grows.

Do I need Redis for Rails 8?

Not usually. Solid Queue, Solid Cache, and Solid Cable keep jobs, cache, and Action Cable messages in your database. You still need Redis for Sidekiq.

Can I run Sidekiq instead of Solid Queue?

Yes. Install Redis on the server, run bundle exec sidekiq as its own supervised process, and set REDIS_URL. Hatchbox adds the Sidekiq process when it finds Sidekiq in your Gemfile, and attaching a Redis database sets REDIS_URL.

Is Kamal or Hatchbox better?

Kamal is free and keeps your whole deploy in the repo, but you run Docker, a registry, backups, and the server itself. Hatchbox costs $15 per server and handles the server, database, SSL, and backups for you, without Docker. See Hatchbox vs Kamal.

How do I get SSL on my Rails VPS?

Use a proxy that talks to Let's Encrypt. kamal-proxy does with ssl: true, Caddy does by default, and Nginx needs certbot. Point your domain's DNS at the server first, because the certificate is only issued once the domain resolves to it.

Simple, predictable pricing.

We charge per server, not per app. Run one application or twenty on the same box — the bill doesn't change.

Start free trial

$15

/server/mo
  • Unlimited applications
  • Deploy anywhere
  • Zero downtime deployments
  • Custom domains & free SSL
  • Databases, cron jobs & background workers
  • Full SSH access to your servers
  • Real, human support
  • 7 day free trial

Ready to deploy your Rails app?

Hatchbox has run more than 2 million deploys across 24,000+ applications since 2016. Start a 7 day free trial and put yours on a server you own.