How to Deploy a Mastodon Instance on Your VPS
Leave a comment on How to Deploy a Mastodon Instance on Your VPS
Mastodon, which offers users total control over their own data and community, has grown in popularity as an open-source substitute for conventional social networks. Hosting Mastodon on your VPS is an effective choice whether you want to run a private social server for your company or use your own instance to join the expanding decentralized Fediverse.

What is Mastodon?
Mastodon is an open-source, decentralized social networking platform that forms part of the Fediverse. Instead of relying on one central server, Mastodon allows anyone to host their own instance while still being able to communicate with users across other servers.
Requirements:
Step 1 – Update Your Server
Start by updating your server packages.
sudo apt update && sudo apt upgrade -y
Install required dependencies:
sudo apt install git curl nano gnupg apt-transport-https build-essential -y
Step 2 – Install PostgreSQL
PostgreSQL is the database backend for Mastodon.
sudo apt install postgresql postgresql-contrib -y
Switch to the PostgreSQL shell and create a database and user:
sudo -u postgres psql
Inside the shell:
CREATE USER mastodon WITH PASSWORD ‘yourpassword’; CREATE DATABASE mastodon_production OWNER mastodon;
\q
Step 3 – Install Redis
Redis is required for caching and background job queues.
sudo apt install redis-server -y
Enable and start Redis:
sudo systemctl enable redis-server
sudo systemctl start redis-server
Step 4 – Install Node.js and Yarn
Mastodon requires Node.js for building the frontend.
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash –
sudo apt install -y nodejs
Install Yarn:
corepack enable
corepack prepare yarn@stable –activate
Step 5 – Install Ruby (via RVM or rbenv)
Example using rbenv:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bashrc source ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Install Ruby:
rbenv install 3.2.2
rbenv global 3.2.2
Step 6 – Install Mastodon
Clone the Mastodon source:
git clone https://github.com/mastodon/mastodon.git
cd mastodon
Check out the latest stable release:
git checkout $(git tag | sort -V | tail -1)
Install Ruby gems:
bundle install
Install JavaScript dependencies:
yarn install –production
Step 7 – Configure Mastodon
Create the environment configuration:
cp .env.production.sample .env.production
Edit the configuration:
vi .env.production
Set values such as:
- LOCAL_DOMAIN
- PostgreSQL credentials
- Redis URL
- Email settings
- Media storage paths
When done, run database setup:
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:precompile
Step 8 – Configure Nginx and SSL
Install Nginx:
sudo apt install nginx -y
Create a Mastodon site configuration under /etc/nginx/sites-available/mastodon.
Once done, enable it:
sudo ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/
Restart Nginx:
sudo systemctl restart nginx
Enable HTTPS
Using Certbot:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot –nginx -d yourdomain.com
Step 9 – Set Up Mastodon Services
Create systemd service files for:
- Web
- Streaming
- Sidekiq workers
Then enable and start services:
sudo systemctl enable –now mastodon-web mastodon-sidekiq mastodon-streaming
Check status:
sudo systemctl status mastodon-web
Step 10 – Access Your Instance
Once everything is running, open your browser and visit: https://yourdomain.com. A brand-new instance of Mastodon will be displayed. Create your admin account, log in, and begin configuring.
Conclusion
Running your own Mastodon instance on a VPS gives you full ownership and control over your online community. While the installation process involves several components working together, the result is a powerful, secure, and customizable social platform that operates independently and still connects seamlessly with the wider Fediverse. When you host Mastodon yourself, your data and rules remain in your control, regardless of whether you are creating a space for friends, an organization, or a public community. With proper setup and occasional maintenance, your server can grow into a stable and meaningful hub for conversation and connection on your own terms.