Before you choose to install your tools, you should try to install the base system. When talking about the base system, we mean the basic tools that make a server work. On your local machine (the development machine), you probably don’t need a lot or have everything already installed. You just start your development server with rails server and everything works. This is not true for the production machine. You need to setup a few things (some of which you must have one on your development machine too!) before you can actually proceed with the installation of tools from the Ruby realm (rails, gems, environment manager and so on).

Operating system

You probably don’t think about this a lot because it’s always there, isn’t it? However, when deploying to production, the OS matters. You need something which is stable, is well known by a lot of folks - so that just in case you fall into a trouble, there are a number of people to help you solve an issue. Ubuntu fits the need and in this guide I am assuming that you would be using Ubuntu 18.04 LTS which is a pretty famous operating system. Thankfully, most cloud hosting providers ask you for nothing but a hostname and the hardware capacity. Select Ubuntu 18.04 LTS and start it.

Setting up SSH for passwordless access

For accessing your server, you would have to login to it. When you install the OS, you would probably receive the username and password so that you can log into your server remotely using SSH. The normal procedure (which most cloud service providers would set you up with) is to login using your username and password. Given your server IP is 10.20.30.40 and the username is ubuntu, you would normally type ssh ubuntu@10.20.30.40 and it would ask you for the password. You enter your password and you are logged in to the machine. However, you need to setup the server to let you in without asking the password. For this, you need to setup a SSH key-pair on your machine and add the public key on the remote server. If you do not know how to do that, here is an excellent guide for that.

Install nginx on the server

We have already talked about the web server, and its importance. So it’s important that we install our web server right away. To install nginx, you need to type this at your terminal:

sudo apt install nginx

NOTE: any command prepended by sudo might ask you for your password (depending on the configuration). Enter your user (not root user) password to proceed. {: .notice—info}

Once it gets installed, hitting the IP address (in our case 10.20.30.40) should show the nginx default page.

NOTE: We will configure nginx later in the guide. {: .notice—info}

Install your database

You probably are going to use a database with your Rails app. You should have it installed. Remember that when downloading and installing Gems (later in the tutorial), you would need certain tools to build native extentions; and that demands the development headers of your database server to be present as well.

For PostgreSQL

Run the following to install PostgreSQL and its development headers:

sudo apt install postgresql libpq-dev

Remember that this is going to install the default version available in Ubuntu’s repositories. If you want to install a specific version, see the official page for Ubuntu here. If you are looking for installation of PostgreSQL on another Linux, you should have a look at their downloads page.

IMPORTANT NOTE: The guide asks you to replace your version in one of the commands. You have to use the release name and not the version number of your distro. So the command deb http://apt.postgresql.org/pub/repos/apt/ YOUR_UBUNTU_VERSION_HERE-pgdg main would become deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main for Ubuntu 18.04. {: .notice—danger}

For SQLite

Run the following to install SQLite 3 and its development header files:

sudo apt install sqlite3 libsqlite3-dev

Install Yarn

For running the precompilation of assets (the asset pipeline), you would need the yarn tool. Install it with:

sudo apt install yarn

Let’s proceed to the next step!