All the information you need on how to install and run your own Mastodon server.
It will probably comes as no surprise to anyone who’s been following the news lately that a certain social network is coming undone and a mass exodus has begun. Many of whom are flocking to the Fediverse via the most popular federated network, Mastodon.
I won’t go into details on what the fediverse is or why you’ll want to interact with it, for that you can read my other posts. If you want to install and run Mastodon on a Ubuntu 22.04 server installation, continue below.
I’m going to assume at this point you have either installed Ubuntu 22.04 LTS server on bare metal, launched one from a cloud provider like Digital Ocean, or installed one via a VM from Virtual Box, etc.
At this point, you should have a server up and running and are logged into the console either directly or via an SSH connection.
You’ll also need a domain name pointing to the IP address of this server, again via your provider, Cloudflare, etc. Whether this is a dedicated IP address or one from your ISP is up to you, see my other posts for running Mastodon from your ISP.
- Ubuntu 22.04 LTS is installed and running.
- Logged into Root. (How to login to root).
- A domain name is pointed to this server.
- Either an SSL cert for the domain or use LetsEncrypt (see below)
We should first update any packages before installing our required set. If you haven’t at this point, make sure you have switched to the root account (sudo -s) or use the sudo command:
apt-get update -y apt-get upgrade -y
After updating and outdated packages, paste the following required dependencies:
apt-get install software-properties-common dirmngr apt-transport-https ca-certificates redis-server curl gcc g++ make imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core libprotobuf-dev protobuf-compiler pkg-config autoconf bison build-essential libssl-dev libyaml-dev libreadline-dev libidn11-dev libicu-dev libjemalloc-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev -y
Next we’ll install Node.js
curl -sL https://deb.nodesource.com/setup_16.x | bash -
Then install Node.js
apt-get install nodejs -y
We’ll need Yarn next, we’ll go ahead and add the repository by accepting the PGP key.
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get update -y
apt-get install yarn -y
PostgreSQL next for our database
apt-get install postgresql postgresql-contrib -y
Switch to the postgres account (again, make sure you’re logged in as root to swap)
su - postgres
If you’ve successfully switched accounts, you can now access postgres by typing in:
Once logged in to postgres, type in the following command to add user:
CREATE USER mastodon CREATEDB;
You can now exit postgres with the following:
We’re now going to create a separate account for running Mastodon, type:
adduser --disabled-login --gecos 'Mastodon Server' mastodon
We’ll now change from root to the mastodon account.
su - mastodon
We’re going to install the Ruby environment repository for installing the required version of Ruby for Mastodon.
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Finally we’ll finish by declaring the version we want:
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.0.3
After installation we’ll set the version of Ruby
rbenv global 3.0.3
Next we’ll update gem and the bundler before we install mastodon.
gem update --system
gem install bundler --no-document