Installing Mastodon on Ubuntu Server Latest

Mastodon is a free and decentralized social media platform. It is an open-source software that allows users to control their data and privacy. In this tutorial, we will guide you on how to install Mastodon on Ubuntu Server Latest.

Prerequisites

Before we begin, make sure that you have the following:

Step 1: Update the system

To update your system, run the following commands:

sudo apt update
sudo apt upgrade

Step 2: Install the necessary packages

Mastodon requires some packages to run correctly. You can install them by running the command below:

sudo apt install imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core g++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev nginx redis-server

Step 3: Configure PostgreSQL

Mastodon uses PostgreSQL as its database. You need to create a user and a database for Mastodon. Run the commands below to do so:

sudo -u postgres createuser mastodon -P --interactive
sudo -u postgres createdb mastodon_production -O mastodon

Step 4: Clone Mastodon

Clone Mastodon from GitHub:

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

Step 5: Install Ruby

Mastodon requires Ruby 2.6.0 or higher. You can use RVM (Ruby Version Manager) to install Ruby. Run the commands below in your Mastodon directory:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.7.0
gem update --system
gem install bundler

Step 6: Configure Mastodon

Copy the default configuration files:

cp .env.production.sample .env.production
cp config/database.yml.sample config/database.yml
cp config/secrets.yml.sample config/secrets.yml

Modify the configuration files to match your server configuration. Edit the .env.production file and define your domain name:

LOCAL_DOMAIN=yourdomain.com

Step 7: Bootstrap Mastodon

To bootstrap Mastodon, run the following commands in your Mastodon directory:

RAILS_ENV=production bundle install --deployment --without development test
RAILS_ENV=production bundle exec rails db:setup
RAILS_ENV=production bundle exec rails assets:precompile

These commands will install the required gems, create the database schema, and compile the assets.

Step 8: Start Mastodon

You can start Mastodon by running the following command in your Mastodon directory:

RAILS_ENV=production bin/tootctl start

Step 9: Configure Nginx

You need to configure Nginx to serve Mastodon. Create a new Nginx configuration file with the following content:

upstream mastodon {
  server 127.0.0.1:3000 fail_timeout=0;
}

server {
  listen 80;
  server_name yourdomain.com;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl http2;
  server_name yourdomain.com;

  ssl on;
  ssl_certificate /path/to/ssl/certificate;
  ssl_certificate_key /path/to/ssl/certificate/key;

  keepalive_timeout 70;
  sendfile on;

  client_max_body_size 100m;

  root /home/yourusername/mastodon/public;

  gzip on;
  gzip_http_version 1.0;
  gzip_proxied any;
  gzip_min_length 0;
  gzip_comp_level 6;
  gzip_types text/plain text/css text/javascript application/json application/javascript application/activity+json application/ld+json application/rss+xml application/atom+xml image/svg+xml;

  location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Frame-Options SAMEORIGIN;
    proxy_pass http://mastodon;
    proxy_buffering off;
    proxy_request_buffering off;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    chunked_transfer_encoding off;
  }

  location /media {
    add_header Cache-Control "public, max-age=31536000, immutable";
  }

  location /sw.js {
    add_header Cache-Control "public, max-age=0";
  }

  error_page 500 501 502 503 504 /500.html;
  location = /500.html {
    root /home/yourusername/mastodon/public;
  }
}

Replace yourdomain.com with your domain name, /path/to/ssl/certificate with your SSL certificate path, and yourusername with your actual username.

After you have modified the file, save it and exit. Then, restart Nginx with the following command:

sudo systemctl restart nginx.service

Conclusion

That's it! You have successfully installed Mastodon on Ubuntu Server Latest. You can now create your account and start using Mastodon.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!