Docs / Programming & Development / Setting Up a Ruby on Rails Application on a VPS

Setting Up a Ruby on Rails Application on a VPS

By Admin · Feb 25, 2026 · Updated Apr 25, 2026 · 101 views · 2 min read

Install Ruby with rbenv

sudo apt install -y git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev

# Install rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
source ~/.bashrc

# Install ruby-build
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

# Install Ruby
rbenv install 3.3.0
rbenv global 3.3.0

Install Rails and Dependencies

gem install rails bundler
sudo apt install -y nginx postgresql postgresql-contrib libpq-dev nodejs npm
sudo npm install -g yarn

Deploy Application

cd /var/www
git clone https://github.com/yourname/myapp.git
cd myapp
bundle install --deployment --without development test
RAILS_ENV=production rails db:create db:migrate
RAILS_ENV=production rails assets:precompile

Puma Service

Create /etc/systemd/system/puma.service:

[Unit]
Description=Puma Rails Server
After=network.target

[Service]
User=deploy
WorkingDirectory=/var/www/myapp
ExecStart=/home/deploy/.rbenv/shims/bundle exec puma -C config/puma.rb
Environment=RAILS_ENV=production
Environment=SECRET_KEY_BASE=your-secret-key
Restart=on-failure

[Install]
WantedBy=multi-user.target

Nginx Configuration

upstream rails {
    server unix:/var/www/myapp/tmp/sockets/puma.sock;
}

server {
    listen 80;
    server_name example.com;
    root /var/www/myapp/public;

    location / {
        try_files $uri @rails;
    }

    location @rails {
        proxy_pass http://rails;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location ~ ^/(assets|packs) {
        expires max;
        gzip_static on;
    }
}

SSL

sudo certbot --nginx -d example.com

Was this article helpful?