How to Install Mastodon Social Network CMS on Ubuntu Linux

fili santillan HeyFNqApSLQ unsplash
fili santillan HeyFNqApSLQ unsplash

The article provides a detailed walkthrough on how to install and use the Mastodon social networking CMS on Ubuntu Linux. Mastodon, a free and open-source CMS supports microblogging features; it is self-hosted, and supports interaction via mobile devices. The installation process involves steps such as setting up dependencies, installing Node.js, Yarn, PostgreSQL, Ruby, and finally setting up Mastodon along with managing its services and setting up an SSL certification.

This article describes installing Mastodon social networking CMS on Ubuntu Linux.

Mastodon is free, open-source CMS software that lets you create your social networking website. It is written in Ruby and JavaScript with support on multiple platforms.

Like Twitter and Facebook, Mastodon offers microblogging features that allow users to post messages, including images, follow others, and create other content.

You can self-host Mastodon on your server in your environment. Users can interact with your server via mobile devices, including Android, macOS, and others.

How to Install Mastodon Social Network CMS on Ubuntu Linux

As described above, Mastodon is free and open-source CMS-based software that lets you create your social networking portal. The app is written in Ruby and JavaScript with support on multiple platforms.

Below is how to install it on Ubuntu Linux.

Install dependencies

First, prepare and install package dependencies, allowing you to install and run Mastodon.

Run the commands below to update Ubuntu and install dependencies for Mastodon.

sudo apt update
sudo apt 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

Once you have installed the packages above, continue below.

Install Node.js and Yarn

Mastodon is written in JavaScript (Node.js). Therefore, it requires Node.js to be installed. Run the commands below to install it.

Add the Node.js repository to Ubuntu by running the commands below.

curl -sL | sudo bash -

After that, run the commands below to install Node.js.

sudo apt install nodejs

Additional Node.js resources can be found in the post below.

How to install Node.js on Ubuntu Linux

After installing Node.js, go and also install Yarn.

Run the commands below to add Yarn’s repository GPG key and file.

curl -sL | sudo apt-key add -
echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Finally, run the commands below to update the Ubuntu package index and install Yarn.

sudo apt update
sudo apt install yarn

Additional Yarn resources can be found in the post below:

How to install Yarn on Ubuntu Linux

Install PostgreSQL

Mastodon needs a database server to store its content. It uses the PostgreSQL database server for that.

Run the commands below to install PostgreSQL.

sudo apt install postgresql postgresql-contrib

After installing, log on to the PostgreSQL database shell.

sudo su - postgres

Run the commands below to create a Mastodon user on the command shell.


Exit twice.


Additional resources on PostgreSQL can be found in the post below.

How to install PostgreSQL on Ubuntu Linux.

Install Ruby

Again, Mastodon is developed in Ruby on Rails. It needs Ruby installed to function. We will create a system account to create an environment to run Ruby.

Run the commands below to create a system account named Mastodon.

sudo adduser --disabled-login --gecos 'Mastodon Server' mastodon

Next, switch to the account by typing the commands below.

sudo su - mastodon

Then, create a Ruby environment.

git clone ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec bash
git clone ~/.rbenv/plugins/ruby-build

Finally, install Ruby and update dependencies.

RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.0.3
rbenv global 3.0.3
gem update --system
gem install bundler --no-document

Install Mastodon

At this point, your system should be ready for Mastodon. Run the commands below to switch to the Mastodon account.

sudo su - mastodon

The clone is the latest version of Mastodon.

git clone ~/live
cd ~/live
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)

Next, install all dependencies.

bundle config deployment 'true'
bundle config without 'development test'
bundle install -j$(getconf _NPROCESSORS_ONLN)
yarn install --pure-lockfile

Set up Mastodon by running the commands below.

RAILS_ENV=production bundle exec rake mastodon:setup

Answer the questions to the prompts as shown below.

Your instance is identified by its domain name. Changing it afterward will break things.

Domain name:
Single user mode disables registrations and redirects the landing page to your public profile.
Do you want to enable single user mode? No
Are you using Docker to run Mastodon? No
PostgreSQL host: /var/run/postgresql
PostgreSQL port: 5432
Name of PostgreSQL database: mastodon_production
Name of PostgreSQL user: mastodon
Password of PostgreSQL user: 
Database configuration works! 🎆
Redis host: localhost
Redis port: 6379
Redis password: 
Redis configuration works! 🎆
Do you want to store uploaded files on the cloud? No
Do you want to send e-mails from localhost? No
SMTP server:
SMTP port: 587
SMTP username: 
SMTP password: 
SMTP authentication: plain
SMTP OpenSSL verify mode: none
E-mail address to send e-mails "from": Mastodon <>
Send a test e-mail with this configuration right now? No
This configuration will be written to .env.production
Save configuration? Yes
Now that configuration is saved, the database schema must be loaded.
If the database already exists, this will erase its contents.
Prepare the database now? Yes
Running `RAILS_ENV=production rails db:setup` ...
Created database 'mastodon'
The final step is compiling CSS/JS assets.
This may take a while and consume a lot of RAM.
Compile the assets now? Yes
Running `RAILS_ENV=production rails assets:precompile` ...

You’ll be prompted to create an admin account. Please do it.

All done! You can now power on the Mastodon server 🐘

Do you want to create an admin user straight away? Yes
Username: admin
You can login with the password: 1c9e2ce773933bec6a71dccd9b889d0a
You can change your password once you login.

Exit when all is done above.

Create a Systemd Service for Mastodon

You want to create a systemd service to efficiently manage the Mastodon service. Then, run the commands below to copy pre-configured scripts to use.

sudo cp /home/mastodon/live/dist/mastodon-web.service /etc/systemd/system/
sudo cp /home/mastodon/live/dist/mastodon-sidekiq.service /etc/systemd/system/
sudo cp /home/mastodon/live/dist/mastodon-streaming.service /etc/systemd/system/

Reload systemd daemon

sudo systemctl daemon-reload

Now, you should be able to start all necessary Mastodon services.

sudo systemctl start mastodon-web
sudo systemctl start mastodon-sidekiq
sudo systemctl start mastodon-streaming
sudo systemctl enable mastodon-web
sudo systemctl enable mastodon-sidekiq
sudo systemctl enable mastodon-streaming

Setup Nginx reverse proxy for Mastodon

Mastodon is SSL enabled by default. You must set up an SSL certificate to use with Mastodon. You can use Let’s Encrypt free SSL with Mastodon; below is how to do it.

Run the commands below to install Certbot and Nginx HTTP server.

sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install certbot python3-certbot-nginx

Please read the post below for additional resources on installing and creating Let’s Encrypt SSL certificates for Nginx.

How to set up Let’s Encrypt SSL certificate for Nginx on Ubuntu Linux

After installing, run the commands below to use Mastodon’s default Nginx server block config setting to create the Nginx server block.

sudo cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon.conf
sudo sed -i 's/' /etc/nginx/sites-available/mastodon.conf
sudo ln -s /etc/nginx/sites-available/mastodon.conf /etc/nginx/sites-enabled/

If you can’t get the Let’s Encrypt SSL certificate on your local host, use the default Ubuntu snakeoil certificate in the Nginx server block file at /etc/nginx/sites-available/mastodon.conf.

#Uncomment these lines once you acquire a certificate:

ssl_certificate     /etc/ssl/certs/ssl-cert-snakeoil.pem;
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;

Give Nginx permission to Mastodon’s directory and restart.

sudo chown -R mastodon:www-data /home/mastodon
sudo systemctl restart nginx

Once you’re done, Mastodon should be installed and ready.

Open your browser and browse the domain name specified in the Nginx server block file.
ubuntu linux install mastodon web portal
Ubuntu Linux install mastodon web portal

Log in with the Mastodon account created above.

ubuntu linux mastodon user dashboard
ubuntu Linux mastodon user dashboard

That should do it!


This post showed you how to install and use Mastodon social network CMS on Ubuntu Linux. Please use the comment form below if you find any errors above or have something to add.

Posted by

I love computers; maybe way too much. What I learned I try to share at

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.