You are on page 1of 1

Installing Mastodon
on the Raspberry Pi
by Emmet  Updated Jul 30, 2023

 Intermediate  Servers

   

In this tutorial, we will be showing you how to


install Mastodon on the Raspberry Pi.

Mastodon is a free and open-source software


that allows you to self-host your own social
network on your Raspberry Pi.

This software is a microblogging platform that


is very much like Twitter However, unlike
Twitter, it is possible to use Mastodon to run a
private social network.

Please note that Mastodon is a relatively heavy


piece of software. You will have the best
experience using a Raspberry Pi 4 with at least
2GB of memory.

Additionally, you must be using a 64-bit


operating system due to the newer release of
PostgreSQL we will be utilizing.

Equipment

Below is the equipment we used to set up


Mastodon on our Raspberry Pi.

Recommended

 Raspberry Pi

 Micro SD Card

 Power Supply

 Ethernet Cable or Wi-Fi

Optional
 Raspberry Pi Case

 HDMI Cable

 Monitor

 USB Keyboard

 USB Mouse

This tutorial was tested on a Raspberry PI 400


running the latest version of Raspberry Pi OS
Buster 64-bit.

Before You Begin

Before you begin with Mastodon on your


Raspberry Pi, you will need a few things for the
best experience with this self-hosted social
network.

A domain name to point toward your


Raspberry Pi’s IP address. Mastodon
requires a domain name to operate
correctly. If you try to connect through a
host that hasn’t been configured, it will
block the connection.

If you have a dynamic IP address, we have


a guide on how to set up dynamic DNS on
your Pi.

To use Mastodon locally you can also


specify a domain name like “
pimylifeup.local ” and modify the hosts
file on your system to point that domain to
your Pi’s local IP.

A publicly routable IP address and not one


behind a CG-NAT. You will also need the
ability to port forward ports 80 and 443
to your Raspberry Pi’s local IP.

You should also use a transactional mail


service such as Sendgrid, Mailgun, or
Amazon SES. While this is not required, it
will help ensure emails sent by Mastodon
are more likely to be recieved.

Preparing your Raspberry


Pi to Run Mastodon

Before running the Mastodon software on the


Raspberry Pi, we must install all the software
required to run it.

In the following sections, we will walk you


through setting up everything required to run
Mastodon.

Installing the Software Needed


for Setup

1. Before installing the software needed to run


Mastodon, we should perform an update.

Update the package list cache and any out-of-


date packages using the following two
commands.

Terminal $  Copy

sudo apt update


sudo apt upgrade

2. Once the update completes, we can install


any software we require to set up the various
pieces of software Mastodon relies on for our
Raspberry Pi.

Use the command below to install almost


everything we need to run Mastodon. Even
though we are installing a lot of software, there
are a few more we will still need to set up.

Terminal $  Copy

sudo apt install curl lsb-release im

Creating a User for Mastodon


on your Raspberry Pi

3. With the base software installed, we can


create a user that Mastodon will run under on
our Raspberry Pi.

We can create this user by using the useradd


command, as shown below. This user will have
the name “ mastodon “.

Terminal $  Copy

sudo useradd mastodon -m

By using the “ -m ” option, this command will


create a home directory while making the user.

Installing NodeJS

4. The Mastodon social network relies on the


Node.JS runtime for its streaming functionality.

Before continuing any further, follow our guide


on installing Node.JS onto the Raspberry Pi.

5. Once you have Node.JS installed on your


device, you may safely continue with this
tutorial.

Setting up PostgreSQL for


Mastodon

6. PostgreSQL is the next piece of software we


need to set up on our Raspberry Pi for
Mastodon.

Mastodon will use PostgreSQL to store all of


the data from your self-hosted social network.

We will need to add the official repository to


install the latest version of PostgreSQL.

Start by saving the GPG key for the Postgre


repository to your device by using the following
command.

Terminal $  Copy

curl -L https://www.postgresql.org/m

7.Now that we have added the GPG key for


PostgreSQL, we can add the repository to our
sources list by using the command below.

Terminal $  Copy

echo "deb [arch=arm64 signed-by=/usr

8. As we changed the available repositories,


we need to update the package list cache
again.

Update the package list cache by running the


following command.

Terminal $  Copy

sudo apt update

9. We can finally install PostgreSQL to our


Raspberry Pi for Mastodon to utilize.

To install this database software, run the


command below in the terminal.

Terminal $  Copy

sudo apt install postgresql postgres

Creating a PostgreSQL User for


Mastodon on the Raspberry Pi

10. With PostgreSQL now installed on the


Raspberry Pi, our next step is creating a new
SQL “user” for Mastodon to use when
connecting to the database.

To be able to create this user, we will need to


use the following command to launch the
PostgreSQL CLI.

Terminal $  Copy

sudo -u postgres psql

11. Since PostgreSQL uses the “ ident ” plugin


by default, we only need to ensure the user has
the same name as the user created earlier.

Use the command below within the CLI to


create a Postgre user named “ mastodon “.

postgres >

CREATE USER mastodon CREATEDB;

Using “ CREATEDB ” at the end of the line, we are


telling Postgres that this new user can create
databases. This permission is required for
Mastodon to properly install intself.

12. With the user now created, you can quit


out of the CLI by typing in the following.

postgres >

\q

You might also like