How to Install Mastodon CMS on Ubuntu Linux
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.
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
To install Mastodon CMS on Ubuntu, you first need to install essential software that helps update your system and build code. Your server needs these specific tools to understand and run the code Mastodon is built with, ensuring everything works correctly from the start.
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 software library to include essential compilers and database connectors, such as `libpq-dev` for PostgreSQL. This process ensures your Ubuntu Linux system has the necessary tools to build and run the Mastodon content management system (CMS).
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 requires Node.js version 22.x to handle its interactive features, so we will install this JavaScript tool on your Ubuntu server. Installing Node.js gives your server the ability to run JavaScript applications, which is crucial for Mastodon’s frontend.
Mastodon installation needs a current Node.js version because Node.js handles the frontend assets. This ensures Mastodon’s website elements, like buttons and text, display and work correctly for you.
Your server gains the ability to run JavaScript applications.
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.
corepack enable
Install PostgreSQL
Mastodon needs a database to store all its information like user accounts, posts, and settings, which is why we install PostgreSQL on your Ubuntu server. A database is essential for saving all this data securely, ensuring your Mastodon instance functions properly.
Why is a database needed? A database is essential for saving user accounts, posts, and settings.
A secure database is created on your server.
sudo apt install postgresql postgresql-contrib sudo -u postgres psql CREATE USER mastodon WITH PASSWORD 'your_secure_password'; ALTER USER mastodon CREATEDB; \q
Install Ruby
Since Mastodon is built with Ruby on Rails, we need to install Ruby version 3.3.x on your Ubuntu server using rbenv. Using a specific Ruby version ensures that Mastodon and its components work correctly, as different software requires precise versions to function properly.
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.
Mastodon's general setup involves downloading the application code and installing specific libraries that your Ubuntu server needs to run Mastodon. This step pulls the latest Mastodon files and sets up necessary software components, configuring your server with Mastodon and Mastodon's database structure.
Running the `git pull` command fetches the most recent Mastodon files and installs the exact libraries required for your Mastodon server to function correctly.
Your server is configured with the Mastodon application files, database structure, and web server settings.
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 connect your Mastodon site to the Nginx web server and use systemd to ensure it runs reliably on your Ubuntu server, making it accessible online. Systemd ensures Mastodon starts automatically if your server restarts, while Nginx handles incoming internet traffic, acting as the front door for your site.
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.
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.


[0-9]
Was this guide helpful?
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.
No comments yet — be the first to share your thoughts!