In this tutorial, we will guide and walk you through the process of installing Mastodon on a Debian 9 VPS.
Mastodon is an open-source free social network based on the open web protocol. It uses Ruby on Rails for the back-end, and React.js and Redux for the front-end. This social media platform is a lot like Twitter, with a focus towards text and media sharing. This platform being open-source means that you can run a private social network for your and your friends to use privately and with no ads.
This guide should work on other Linux VPS systems as well, but it was tested and written for a Debian 9 VPS. The install process shouldn’t take too long, the longest part being the compilation process. Let’s begin with the installation.
Table of Contents
Prerequisites:
- A Debian 9 VPS.
- A user account with sudo privileges, or access to the ‘root’ user itself.
Step 1: Install Required Packages
Log in to your VPS via SSH as root or as a sudo user:
Replace “IP_Address” and “Port_Number” with your server’s respective IP address and SSH port numbers. Additionally, replace “username” with ‘root’ for the root user, or with the name of the admin account you plan to use.
Once logged in, issue the following commands to update all installed packages to their latest available versions:
Install the required packages using the following command:
These packages cover all of the requirements for Mastodon, from media conversion, to streaming services.
Step 2: Install Node.js and Yarn
We will install Node.js and Yarn from their official repositories.
Enable the NodeSource repository with the following curl command:
To install Node.js 8.x LTS Carbon and npm, run this next command:
Import the Yarn APT repository’s GPG key and enable it by running:
Install Yarn using the following command:
Step 3: Install PostgreSQL
Mastodon can use PostgreSQL as its database back-end.
If the PostgreSQL server is not already installed on your server, you can install the latest PostgreSQL version by executing the following command:
Once the installation is complete, log in to the PostgreSQL shell:
Create a new user for the Mastodon instance:
Step 4: Install Redis
Installing Redis is pretty straightforward, just run the following command:
Step 5: Create a New System User
Create a new system user that will run the Mastodon server:
Step 6: Install Ruby
We will install Ruby using the Rbenv script.
Before cloning the rbenv repository, switch to the new mastodon user that we created in the previous step:
Set up ‘rbenv’ and ‘ruby-build’ with the following commands:
Once both ‘rbenv’ and ‘ruby-build’ are set, install the latest Ruby version with:
Update the gem and install bundler so that they work with the version of rbenv that we just installed.:
To verify everything is done correctly, use the command ruby --version
.
The output should be similar to the following:
Step 7: Setting up Mastodon
The following commands are also run as mastodon user.
Clone the mastodon git repository into the ~/live
directory and checkout to the latest stable Mastodon branch:
Install the ruby dependencies with the following command:
Install the node.js dependencies with:
Change to the Mastodon installation directory and run the following command to start the setup:
The installer will ask you several questions, generate a new app secret, set up the database schema, and compile the assets. This may take a while, depending on your server’s hardware:
When done, switch back to your sudo user by running:
Step 8: Setting up Nginx
Install Nginx and Certbot using the following command:
Once Nginx is installed, copy the Nginx configuration template from the Mastodon installation directory:
Run the following command to change the Mastodon installation directory path and the domain name. Don’t forget to replace ‘your-domain.com‘ with your registered domain name:
Restart Nginx for changes to take effect:
Next, use certbot to get a free SSL certificate using Let’s Encrypt:
The toll will obtain a free Let’s encrypt SSL certificate and reconfigure the Nginx configuration.
Step 9: Setting up systemd Services
Copy the systemd unit files from the Mastodon directory:
Run the following command to change the Mastodon installation directory path:
Finally, start and enable the new systemd services:
At this point, you can open your domain in the browser and finish up the Mastodon install.
That’s it. You have successfully installed Mastodon on your Debian 9 VPS. For more information about how to manage your Mastodon installation, please refer to the official Mastodon documentation.
Of course, you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, please share it with your friends on the social networks using the share shortcuts below, or simply leave a comment down in the comments section. Thanks.