Skip to content
Follow
CMS Ubuntu Linux

How to Install Mastodon CMS on Ubuntu Linux

Richard
Written by
Richard
Oct 22, 2022 Updated Jun 19, 2026 4 min read
How to Use Sticky Notes in Windows 11
How to Use Sticky Notes in Windows 11

You can install Mastodon CMS on Ubuntu Linux to host your own decentralized social network.

Mastodon is a free, open-source social networking platform that allows you to create and manage your own community, similar to popular microblogging sites. It emphasizes user control and decentralization, letting you own your data and community rules.

This guide focuses on deploying Mastodon version 4.x on an Ubuntu server, giving you a step-by-step process to set up your instance from scratch.

⚡ Quick Answer

Install dependencies using `sudo apt update && sudo apt install` for essential tools. Then install Node.js and Yarn, followed by PostgreSQL for your database. Finally, set up Ruby and download the Mastodon code to complete the installation.

Install Dependencies

Installing Mastodon CMS on Ubuntu starts with getting the basic software your server needs, like tools to update your system and build code.

Why do we need this? Your server requires specific software tools to translate and run the code Mastodon is built with.

Your system updates its library of available software and installs essential compilers and database connectors.

🐧Bash / Shell
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

Install Node.js and Yarn

Mastodon needs Node.js version 22.x to run its interactive parts, so we’ll install this JavaScript tool on your Ubuntu server.

Why do we need this? Mastodon requires a current version of Node.js to handle the frontend assets.

Your server gains the ability to run JavaScript applications.

🐧Bash / Shell
curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install nodejs

How to install Node.js on Ubuntu Linux

Next, enable the Yarn package manager using corepack.

💻Code
corepack enable

How to install Yarn on Ubuntu Linux

Install PostgreSQL

Mastodon needs a database to store all user accounts, posts, and settings, so we’ll install PostgreSQL on your Ubuntu server.

Why is a database needed? A database is essential for saving user accounts, posts, and settings.

A secure database is created on your server.

🐧Bash / Shell
sudo apt install postgresql postgresql-contrib
sudo -u postgres psql
CREATE USER mastodon WITH PASSWORD 'your_secure_password';
ALTER USER mastodon CREATEDB;
\q

How to install PostgreSQL on Ubuntu Linux.

Install Ruby

Mastodon is built using Ruby on Rails, so we need to install Ruby version 3.3.x on your Ubuntu server using rbenv to make sure it works right.

Why is this necessary? Different software needs specific versions of Ruby to work correctly.

You will have a controlled environment to run Ruby version 3.3.x.

Command Prompt
sudo adduser --disabled-login --gecos 'Mastodon Server' mastodon
sudo su - mastodon
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec bash
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install 3.3.6
rbenv global 3.3.6
gem install bundler

General Setup

The general setup for Mastodon involves downloading the application code and installing the specific libraries your Ubuntu server needs to run it.

Why? This pulls the latest files and installs the specific libraries needed for your server.

Your server is configured with the Mastodon application files, database structure, and web server settings.

Command Prompt
git clone https://github.com/mastodon/mastodon.git ~/live
cd ~/live
bundle config deployment 'true'
bundle config without 'development test'
bundle install
corepack prepare yarn@stable --activate
yarn install
RAILS_ENV=production bundle exec rake mastodon:setup

Web Server and Services

We’ll connect your Mastodon site to the Nginx web server and use systemd to make sure it runs reliably on your Ubuntu server, making it accessible online.

Why is this important? Systemd ensures Mastodon starts automatically if your server reboots, and Nginx acts as the front door for internet traffic.

Your site becomes live on the internet.

🐧Bash / Shell
sudo cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now mastodon-web mastodon-sidekiq mastodon-streaming
sudo cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon
sudo ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/
sudo systemctl restart nginx

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

Open your browser and visit your domain to see your new social network.

ubuntu linux install mastodon web portal
Ubuntu Linux install mastodon web portal
ubuntu linux mastodon user dashboard
ubuntu Linux mastodon user dashboard

[0-9]

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Install LibreOffice on Ubuntu Linux
Ubuntu Linux How to Install LibreOffice on Ubuntu Linux
How to Install PowerDNS on Ubuntu Linux
CMS How to Install PowerDNS on Ubuntu Linux
How to Install Additional Software on Ubuntu
Ubuntu Linux How to Install Additional Software on Ubuntu
How to Install sysPass Password Manager on Ubuntu
CMS How to Install sysPass Password Manager on Ubuntu

No comments yet — be the first to share your thoughts!

Leave a Comment

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