How to Use the Ruby on Rails One-Click Application on DigitalOcean
How to Use the Ruby on Rails One-Click Application on DigitalOcean
We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How to Use the Ruby on Rails One-Click Application on DigitalOcean

PostedSeptember 23, 2014 112.6k views Ruby on Rails One-Click Install Apps Ubuntu

Status: Archived

This article exists for historical reference and is no longer maintained.

Reason: This Ruby on Rails One-Click image is no longer offered.

See Instead:


DigitalOcean's Ruby on Rails one-click application provides a convenient way to get your Rails application up and running on an Ubuntu server. With Nginx, Unicorn, and Postgres all pre-installed, the one-click is a great base for hosting your app. This tutorial will give you all the details you need to get your project off the ground.

Included Components

In addition to what comes with a plain Ubuntu 14.04 Droplet, the Ruby on Rails one-click image includes the following components:

  • Ruby 2.2: Ruby language support, installed with RVM
  • Rails 4: The Rails web framework gem
  • PostgreSQL: The most commonly used database server for production Rails application deployments
  • Unicorn: Rails application server
  • Nginx: General purpose HTTP server that is configured as a reverse proxy to Unicorn

It also comes preconfigured with a system user and a database user, both named rails, which are used to deploy applications. For convenience, the git package is installed on the image.

In just a bit, we'll get into the details of how the components are configured, where the login names and passwords can be found, and how to launch your application.

Create Your Ruby on Rails Droplet

If you haven't already done so, create a Droplet from the DigitalOcean Control Panel, and select the Ruby on Rails on 14.04 one-click application image. We'll guide you through the steps.

Note: If you have already created a Droplet with the Ruby on Rails on 14.04 image, you should skip this section.

First, log in to the DigitalOcean Control Panel.

Then click the Create Droplet button.

At the Droplet creation page, specify your desired hostname and size. For a basic application that won't receive much traffic, a 1GB Droplet should be fine:

Droplet Hostname and Size

Select your desired region:

Select region and options

Now, at the Select Image section, click the Applications tab and select the Ruby on Rails on 14.04 image:

Select Ruby on Rails One-Click Application Image

Next, select any additional settings, such as private networking, IPv6, or backups.

Finally, select which SSH keys, if any, you want to use for accessing this Droplet, and hit the Create Droplet button.

Your Ruby on Rails Droplet will be ready soon. For more details about creating Droplets, check out this tutorial: How To Create Your First DigitalOcean Droplet.

How To Access Your Ruby on Rails Droplet

Once your Droplet has been created, you may access it in two ways:

  1. As a user of the running Rails application, by visiting the Droplet's IP address in a web browser
  2. As a server administrator, by connecting as the root user via SSH. This method will be used to deploy your application

Your Droplet's public IP address can be found in the DigitalOcean Control Panel.

Check the Placeholder Rails Application

The one-click application ships with a placeholder Rails application that should be running by default. To see if the sample Rails application is running, visit your Droplet's public IP address in a web browser.

For example, suppose your Droplet's IP address is In this case, you would open in a web browser to verify that Rails is running:

Default Rails page

If you see the sample Rails page, you're ready to log into your server.

Access the Droplet via SSH

To deploy your own Rails application, you will need to connect to your Droplet as root via SSH. Let's do that now.

Note: If you haven't used SSH or PuTTY before, you may want to refer to this tutorial for more details: How To Connect To Your Droplet with SSH.

On your computer, open a terminal and log in to your Droplet as root via SSH with this command (substitute your Droplet's IP address):

  • ssh root@droplet.ip.address

If you are prompted for a password, enter the password that was emailed to you when the Droplet was created. Alternatively, if you set up the Droplet with SSH keys, the keys will be used for authentication instead.

Login Names and Passwords

The Ruby on Rails one-click application comes preconfigured with the following:

  • A system user named rails, which deploys the application
  • A PostgreSQL database user also named rails, which is used by the application to connect to the database

The passwords for both of these logins are randomly-generated, and can be found in the message of the day (MOTD) that will appear whenever you log into the server via SSH. The MOTD should look something like this:

Thank you for using DigitalOcean's Rails Application.
We have created a default Rails application that can be seen from
You can use the following SFTP credentials to upload your webpages (using FileZilla/WinSCP/Rsync):
  * Host:
  * User: rails
  * Pass: PzAaUykNL4
You can use the following Postgres database credentials:
  * User: rails
  * Pass: temq0AtHj7
Nginx listens on public IP ( port 80 and forwards requests to Unicorn on port 8080
Nginx access log is in /var/log/nginx/access.log and error log is in /var/log/nginx/error.log
Unicorn configuration files are in /etc/unicorn.conf and /etc/default/unicorn
Unicorn log is in /var/log/unicorn/unicorn.log
To get a list of available gems: gem list
To get a list of Rubies: rvm list
To get Gem environment: gem env

To simplify the deployment of your application, the automatically generated database password is also located in the /etc/default/unicorn file, as the APP_DATABASE_PASSWORD environment variable.

How To Deploy Your Rails Application

We'll walk you through deploying a sample Rails app that we'll clone from GitHub. If you have your own deployment flow, feel free to read about the one-click application's configuration details, which can be found in the Configuration Details section that follows the application deployment example.

In summary, here are the steps that we will cover:

  • Git clone your application
  • Configure the database connection
  • Update your Gemfile to include unicorn and pg gems, and run bundler
  • Run rake tasks
  • Configure Unicorn
  • Configure Nginx

Let's get started.

Git Clone Your Application

We will assume that you're logged in as the root user. We'll demonstrate how to manually deploy an application, sample_tasks, from a GitHub repository.

First, let's use git to clone the application that you want to deploy to the rails user's home directory. Be sure to substitute your own repository link here, if you want to deploy your own application:

  • cd ~rails
  • git clone

This will clone the respository to the rails home directory. In our example, this means that the application is located in a directory called sample_tasks.

Configure the Database Connection

Now we're ready to configure your application to connect to the PostgreSQL database. For this example, we'll simply copy database configuration for the rails_project app to our new app, then modify it slightly.

Copy the sample application's database.yml file to your app's config directory, like this (subsitute your app's path here):

  • cp ~rails/rails_project/config/database.yml ~rails/sample_tasks/config/

This file is populated with the configuration that will allow your application to connect to the provided PostgreSQL database, but we should change the names of the databases before using it. Open the file in your favorite editor (we'll use nano here):

  • nano ~rails/sample_tasks/config/database.yml

Find every occurrence of "railsproject" (there are three) and replace it with the name of your application—in our example, "sampletasks". If you're using nano, you can find and replace the app name like this: press Ctrl-W, then Ctrl-R, type in "rails_project", then Enter, then type in the name of your application, then Enter, then hit A.

After you've updated the file, the production section should look like this (with your app's name instead of the highlighted "sample_tasks"):

database.yml excerpt
  <<: *default
  database: sample_tasks_production
  username: rails
  password: <%= ENV['APP_DATABASE_PASSWORD'] %>

Save and exit. That's Ctrl-O, Enter, then Ctrl-X, if you're using nano.

Update Gemfile

If your application isn't configured to use PostgreSQL and Unicorn, you should add those gems into the Gemfile. Open the Gemfile in your favorite editor (we'll use nano here):

nano ~rails/sample_tasks/Gemfile

Include the the pg and unicorn gems by adding these lines:

group :production do
  gem 'unicorn'
  gem 'pg'

Take a note of the version of Ruby if is specified.

Save and exit.

Note: If your Gemfile specifies a version of Ruby that is different from the one installed on the system, you may install it using RVM. For example, the example Gemfile specifies Ruby 2.0.0, so we could install it like this:

rvm install 2.0.0
rvm use ruby-2.0.0-p643 --default

Now change to the application's directory and run bundler:

cd ~rails/sample_tasks && bundle install

Run Rake Tasks

We are ready to run our rake tasks but we need to set our environment with the PostgreSQL database user's password. In order to do so, we'll need source the /etc/default/unicorn file (details about this can be found in the Configuration Details section) with this command:

. /etc/default/unicorn

Now run your rake tasks. In our example, we'll create the production database, run any migrations, then precompile our assets:

RAILS_ENV=production rake db:create
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake assets:precompile

At this point, you may want to change the ownership of the application files to the rails user:

chown -R rails: /home/rails/sample_tasks

Configure Unicorn

Now we need to update the Unicorn configuration files to point to the path of our application. Open the /etc/unicorn.conf file for editing:

  • nano /etc/unicorn.conf

Find the line that specifies the working_directory and replace its value with your application's path. You can use the same find and replace trick that we used for the database configuration file. When you're done, the line should look something like this (with your application's actual path):

/etc/unicorn.conf excerpt
working_directory "/home/rails/sample_tasks"

Save and exit.

Next, edit the /etc/default/unicorn file:

  • nano /etc/default/unicorn

Find the line that specifies APP_ROOT, and update it to point to your application. Again, this is a matter of finding and replacing "rails_project" with your app's name. When you're done, the line should look like this:

/etc/default/unicorn excerpt

The application is ready to go. Restart Unicorn to load it:

service unicorn restart

Our application deployment is almost complete. We just need to reconfigure Nginx slightly.

Update Nginx Configuration

Nginx, which is used as a reverse proxy to Unicorn, needs to know the path of your application's public directory. Open the Nginx configuration file, with this command:

  • nano /etc/nginx/sites-enabled/rails

Find the line that specifies root, and change it so it points to your application's public directory. Again, this is a matter of replacing "rails_project" with the name of your application. The line should look something like this when you're done:

/etc/nginx/sites-enabled/rails excerpt
    root /home/rails/sample_tasks/public;

Save and exit.

Now reload Nginx to put the changes into effect:

  • service nginx reload

Access Your Rails App

You now should be able to access your application by accessing your Droplet's public IP address in a web browser: http://droplet.ip.address. If you followed the example exactly, you will want to access it by going to `http://droplet.ip.address/tasks, as it doesn't have a default index page.

Congratulations on deploying your Ruby on Rails application!

If you want to learn more about your Droplet's setup, or customize it further, it is strongly encouraged that you read the next section.

Configuration Details

The Rails project is served by Unicorn which listens on the unix socket and is reverse proxied by Nginx which listens on port 80.


The Nginx configuration is located at /etc/nginx/sites-enabled/rails. The root directive should be set to your application's directory. You can customize it to add SSL certificates and add other upstream servers if needed:

  • upstream app_server {
  • server unix:/var/run/unicorn.sock fail_timeout=0;
  • }
  • server {
  • listen 80;
  • root /home/rails/rails_project/public;
  • server_name _;
  • index index.htm index.html;
  • location / {
  • try_files $uri/index.html $uri.html $uri @app;
  • }
  • location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
  • try_files $uri @app;
  • }
  • location @app {
  • proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  • proxy_set_header Host $http_host;
  • proxy_redirect off;
  • proxy_pass http://app_server;
  • }
  • }

Once Nginx receives a request on port 80, it serves the static content such as images, and forwards the request to Unicorn, which listens on a unix socket at /var/run/unicorn.sock.


Unicorn is used to serve Ruby on Rails applications and looks for files in the specified working_directory, which is set to /home/rails/rails_project by default. This should be updated to the path of your application.

We added a minimal Unicorn configuration in /etc/unicorn.conf which specifies the path of the socket to listen to, how many workers to spawn, and where to store the log files:

  • listen "unix:/var/run/unicorn.sock"
  • worker_processes 4
  • user "rails"
  • working_directory "/home/rails/rails_project"
  • pid "/var/run/"
  • stderr_path "/var/log/unicorn/unicorn.log"
  • stdout_path "/var/log/unicorn/unicorn.log"

The other important configuration file is in /etc/default/unicorn and specifies configuration file location and, more importantly, Ruby, Gem, and Daemon paths as well as randomly generated SECRET_KEY_BASE and APP_DATABASE_PASSWORD. You will need to update the APP_ROOT to specify the path of your application:

  • # Change paramentres below to appropriate values and set CONFIGURED to yes.
  • # Default timeout until child process is killed during server upgrade,
  • # it has *no* relation to option "timeout" in server's config.rb.
  • TIMEOUT=60
  • # Path to your web application, sh'ld be also set in server's config.rb,
  • # option "working_directory". Rack's is located here.
  • APP_ROOT=/home/rails/rails_project
  • # Server's config.rb, it's not a rack's
  • CONFIG_RB=/etc/unicorn.conf
  • # Where to store PID, sh'ld be also set in server's config.rb, option "pid".
  • PID=/var/run/
  • RAILS_ENV="production"
  • PATH=/usr/local/rvm/rubies/ruby-2.2.1/bin:/usr/local/sbin:/usr/bin:/bin:/sbin:/usr/local/rvm/bin:/usr/local/rvm/gems/ruby-2.2.1@global/bin:/usr/local/rvm/gems/ruby-2.2.1/bin/
  • export GEM_HOME=/usr/local/rvm/gems/ruby-2.2.1
  • export GEM_PATH=/usr/local/rvm/gems/ruby-2.2.1:/usr/local/rvm/gems/ruby-2.2.1@global
  • DAEMON=/usr/local/rvm/gems/ruby-2.2.1/bin/unicorn
  • # Generate by running `rake -f /home/rails/Rakefile secret`
  • export SECRET_KEY_BASE=e9a806f70df01968fdda069f009690b2a09a168e5b495aed217090a8cb5ef4b76f82d7efa430409c968996ffa43ef9393d4e1cdb82dc7549cc8fcd2beb0d0338
  • export APP_DATABASE_PASSWORD=temq0AtHj7

Ruby Version Manager

Since some Rails applications may require different Ruby versions, we have used Ruby Version Manager (rvm) to install Ruby.

This allows you to have multiple Ruby versions installed on your server that are then used by different applications.

Currently, Ruby version 2.2.1 is used as the default version.

If your application requires a different version of Ruby, for example 2.0.0, you can install it using RVM:

  • rvm install 2.0.0

To modify your default Ruby version with RVM, use:

  • rvm use ruby-2.0.0-p643 --default

You can get a list of known Ruby versions by running the command rvm list known

If you would like to install the latest Ruby currently available:

  • rvm install ruby --latest
  • rvm use ruby --latest --default

If you change the Ruby version, you would also need to update Unicorn's config in /etc/default/unicorn and modify paths for Ruby version that you have installed. Find out where Ruby is located:

Example terminal:
root@rails:~# which ruby /usr/local/rvm/rubies/ruby-2.0.0-p643/bin/ruby root@rails-testing:~# rvm list rvm rubies => ruby-2.0.0-p643 [ x86_64 ] * ruby-2.2.1 [ x86_64 ] # => - current # =* - current && default # * - default root@rails:~# rvm use ruby-2.2.1 --default Using /usr/local/rvm/gems/ruby-2.2.1 root@rails:~# rvm list rvm rubies ruby-2.0.0-p643 [ x86_64 ] =* ruby-2.2.1 [ x86_64 ] # => - current # =* - current && default # * - default root@rails:~# which ruby /usr/local/rvm/rubies/ruby-2.2.1/bin/ruby root@rails:~# ruby -v ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]

You should also install Unicorn, Rails, and Bundler gems for the new Ruby installation:

  • gem install bundler rails unicorn

Once you have the location of Ruby that you are using by default, change /etc/default/unicorn pathnames to include /usr/local/rvm/rubies subfolder and /usr/local/rvm/gems subfolders for the newly installed version as well as location of Unicorn:

/etc/default/unicorn excerpt
  • PATH=/usr/local/rvm/rubies/ruby-2.2.1/bin:/usr/local/sbin:/usr/bin:/bin:/sbin:/usr/local/rvm/bin:/usr/local/rvm/gems/ruby-2.2.1@global/bin:/usr/local/rvm/gems/ruby-2.2.1/bin/
  • export GEM_HOME=/usr/local/rvm/gems/ruby-2.2.1
  • export GEM_PATH=/usr/local/rvm/gems/ruby-2.2.1:/usr/local/rvm/gems/ruby-2.2.1@global
  • DAEMON=/usr/local/rvm/gems/ruby-2.2.1/bin/unicorn

You would also need to install any other gems your application requires in Gemfile:

  • cd /home/rails && bundle install

After you have installed the necessary gems, you should restart Unicorn with:

  • sudo service unicorn restart

Check the log file in /var/log/unicorn/unicorn.log and if you see any Bundler::GemNotFound errors, then you would have to install missing gems.

Use the following command to continuously monitor the log output:

  • tail -f /var/log/unicorn/unicorn.log

A sample error line would look like this:

  • Could not find i18n-0.6.1 in any of the sources (Bundler::GemNotFound)

For this particular error you may need to install specific version of i18n gem:

  • gem install i18n -v 0.6.1

If you have an error that a more recent version is already installed (for example i18n-0.9.0, simply uninstall that gem and install correct one:

  • gem uninstall i18n -v 0.9.0
  • gem install i18n -v 0.6.1

Uploading Files

We recommend that you use SFTP (Secure FTP), SCP, or Rsync to upload your files, as they all use encryption for transmission of data.

Windows users can upload files with WinSCP. For all other operating systems (including Windows) you can use FileZilla and Rsync.

For seasoned developers, we have an article on how to setup Git

The root of your Rails application should be in a directory in /home/rails, e.g. /home/rails/rails_project. Nginx and Unicorn will look for public pages in /home/rails/rails_project/public, unless you reconfigured them—be sure to upload your files using SFTP accordingly.

Your SFTP credentials are provided in the Message of the Day (credentials are different and randomly generated for every droplet) and are also available in /etc/motd.tail for your review.

Postgres Database Credentials

The one-click installation includes a Postgres database for you to use (credentials are different and randomly generated for each droplet).

A previous version of this application image used MySql as its default database. If you are using that version, the randomly generated MySQL root password can be found in in /root/.my.cnf

The database credentials for the rails user are also saved in /etc/motd.tail and displayed in Message of the Day as seen above. They are also exported as the environmental variable APP_DATABASE_PASSWORD in /etc/default/unicorn The sample Rails project that is pre-installed reads this in its database configuration (/home/rails/config/database.yml) using:


Next Steps


Creative Commons License