Introduction

Mastodon is a free and open-source self-hosted social networking platform. This tutorial will guide you through the process of installing Mastodon on Debian 12.

Prerequisites

Before you begin, ensure you have:

  1. A Debian 12 server or virtual machine
  2. SSH access to the server
  3. Root or sudo privileges
  4. A domain name pointed to your server's IP address (optional)

Step 1: Update System

Before installing any new software, it's always a good idea to update the package repository and installed packages:

sudo apt update
sudo apt upgrade -y

Step 2: Install Dependencies

Install the required dependencies for Mastodon:

sudo apt install -y imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git curl g++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf bison build-essential libssl-dev libyaml-dev libreadline-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev nginx redis redis-server postgresql postgresql-contrib letsencrypt yarn

Step 3: Set Up PostgreSQL

Create a PostgreSQL user and database for Mastodon:

sudo -u postgres createuser -s mastodon
sudo -u postgres psql -c "ALTER USER mastodon WITH PASSWORD 'your_password';"
sudo -u postgres createdb -O mastodon mastodon_production

Step 4: Install Ruby

Install Ruby using rbenv:

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

rbenv install 3.0.2
rbenv global 3.0.2
ruby -v

Step 5: Install Mastodon

Clone the Mastodon repository:

git clone https://github.com/tootsuite/mastodon.git ~/live
cd ~/live

Install Mastodon dependencies:

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

Step 6: Configure Mastodon

Generate Mastodon configuration files:

RAILS_ENV=production bundle exec rake mastodon:setup

Follow the on-screen prompts to configure Mastodon. Make sure to enter your domain name when prompted.

Step 7: Precompile Assets

Precompile Mastodon assets:

RAILS_ENV=production bundle exec rails assets:precompile

Step 8: Set Up Nginx

Set up Nginx configuration for Mastodon:

sudo cp ~/live/dist/nginx.conf /etc/nginx/sites-available/mastodon
sudo ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon

Open the Nginx configuration file and replace example.com with your domain name:

sudo nano /etc/nginx/sites-available/mastodon

Restart Nginx to apply the changes:

sudo systemctl restart nginx

Step 9: Start Mastodon Services

Start Mastodon services:

cd ~/live
RAILS_ENV=production bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push
RAILS_ENV=production bundle exec puma -C config/puma.rb

Step 10: Set Up Let's Encrypt SSL

Install Certbot for Let's Encrypt:

sudo apt install certbot

Obtain SSL certificate for your domain:

sudo certbot --nginx -d your_domain_name

Follow the on-screen prompts to obtain and install the SSL certificate.

Step 11: Access Mastodon

Open a web browser and navigate to your Mastodon instance using your domain name:

https://your_domain_name

Follow the on-screen instructions to set up your Mastodon instance and create an administrator account.

Conclusion

Congratulations! You have successfully installed Mastodon Social Network on Debian 12. You can now customize your Mastodon instance and start connecting with others in the Fediverse.

Was this answer helpful? 0 Users Found This Useful (0 Votes)