Installing from source
Pre-requisites
A machine running Ubuntu 18.04 that you have root access to
A domain name (or a subdomain) for the Mastodon server, e.g.
example.com
An e-mail delivery service or other SMTP server
You will be running the commands as root. If you aren’t already root, switch to root:
System repositories
Make sure curl is installed first:
Node.js
Yarn
System packages
Installing Ruby
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:
We can then switch to the user:
And proceed to install rbenv and rbenv-build:
Once this is done, we can install the correct Ruby version:
Default gem version shipped with ruby_2.6.0 is incompatible with latest bundler, so we need to update gem:
We’ll also need to install bundler:
Return to the root user:
Setup
Setting up PostgreSQL
Performance configuration (optional)
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:
In the prompt, execute:
Done!
Setting up Mastodon
It is time to download the Mastodon code. Switch to the mastodon user:
Checking out the code
Use git to download the latest stable release of Mastodon:
Installing the last dependencies
Now to install Ruby and JavaScript dependencies:
Generating a configuration
Run the interactive setup wizard:
This will:
Create a configuration file
Run asset precompilation
Create the database schema
You’re done with the mastodon user for now, so switch back to root:
Setting up nginx
Copy the configuration template for nginx from the Mastodon directory:
Then edit /etc/nginx/sites-available/mastodon
to replace example.com
with your own domain name, and make any other adjustments you might need.
Reload nginx for the changes to take effect:
Acquiring a SSL certificate
We’ll use Let’s Encrypt to get a free SSL certificate:
This will obtain the certificate, automatically update /etc/nginx/sites-available/mastodon
to use the new certificate, and reload nginx for the changes to take effect.
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:
Then edit the files to make sure the username and paths are correct:
/etc/systemd/system/mastodon-web.service
/etc/systemd/system/mastodon-sidekiq.service
/etc/systemd/system/mastodon-streaming.service
Finally, start and enable the new systemd services:
They will now automatically start at boot time.
Hurray! This is it. You can visit your domain in the browser now!
Last updated
Was this helpful?