We will be using rbenv to manage Ruby versions, because it's easier to get the right versions and to update once a newer release comes out. rbenv must be installed for a single Linux user, therefore, first we must create the user Mastodon will be running as:
For optimal performance, you may use [pgTune](https://pgtune.leopard.in.ua/#/) to generate an appropriate configuration and edit values in `/etc/postgresql/9.6/main/postgresql.conf` before restarting PostgreSQL with `systemctl restart postgresql`
#### Creating a user
You will need to create a PostgreSQL user that Mastodon could use. It is easiest to go with "ident" authentication in a simple setup, i.e. the PostgreSQL user does not have a separate password and can be used by the Linux user with the same username.
Open the prompt:
```sh
sudo-u postgres psql
```
In the prompt, execute:
```
CREATE USER mastodon CREATEDB;
\q
```
Done!
### Setting up Mastodon
It is time to download the Mastodon code. Switch to the mastodon user:
```sh
su - mastodon
```
#### Checking out the code
Use git to download the latest stable release of Mastodon:
```sh
git clone https://github.com/tootsuite/mastodon.git live &&cd live
The configuration file is saved as `.env.production`. You can review and edit it to your liking. Refer to the [documentation on configuration]({{<relref"configuration.md">}}).
You're done with the mastodon user for now, so switch back to root:
```sh
exit
```
### Setting up nginx
Copy the configuration template for nginx from the Mastodon directory:
You can now edit `/etc/nginx/sites-available/mastodon` to uncomment and adjust the `ssl_certificate` and `ssl_certificate_key` lines.
Then, reload nginx for the changes to take effect:
```sh
systemctl reload nginx
```
At this point you should be able to visit your domain in the browser and see the elephant hitting the computer screen error page. This is because we haven't started the Mastodon process yet.
### Setting up systemd services
Copy the systemd service templates from the Mastodon directory: