Mastodon is a free, open-source social network that allows users to create their own communities and share their thoughts and ideas. In this article, we will show you how to install Mastodon on Ubuntu 22.04.
Before we begin, make sure you have the following prerequisites installed on your system:
- Git
- Ruby
- PostgreSQL
- Yarn
- Node.js
- Redis
- Nginx
To install Git, Ruby, PostgreSQL, Yarn, and Node.js, you can use the following commands:
sudo apt-get install git ruby postgresql yarn nodejs
To install Redis, you can use the following command:
sudo apt-get install redis-server
To install Nginx, you can use the following command:
sudo apt-get install nginx
Once you have all the prerequisites installed, you can proceed with the installation of Mastodon.
The first step is to create a new user for Mastodon and switch to that user. This is recommended for security reasons. You can do this using the following commands:
sudo adduser --disabled-login mastodon
sudo su - mastodon
Next, clone the Mastodon repository from GitHub using the following command:
git clone <https://github.com/tootsuite/mastodon.git>
This will download the latest version of Mastodon to a directory called mastodon
in your current user’s home directory.
Now, navigate to the mastodon
directory and install the dependencies using the following commands:
cd mastodon
bundle install
yarn install
Once the dependencies are installed, you can create a new configuration file for Mastodon. You can do this by copying the sample configuration file and modifying it according to your requirements:
cp .env.production.sample .env.production
Next, you will need to create a new database for Mastodon. You can do this using the following commands:
sudo -u postgres psql
CREATE USER mastodon CREATEDB;
CREATE DATABASE mastodon_production OWNER mastodon;
\\q
Once the database is created, you can migrate the database schema using the following command:
RAILS_ENV=production bundle exec rails db:migrate
Now, you can precompile the Mastodon assets using the following command:
RAILS_ENV=production bundle exec rails assets:precompile
Once the assets are precompiled, you can start the Mastodon web server using the following command:
RAILS_ENV=production bundle exec rails s
This will start the Mastodon web server on port 3000
.
To serve Mastodon using Nginx, you will need to create a new virtual host configuration file. You can do this by creating a new file called mastodon.conf
in the /etc/nginx/conf.d
directory and adding the following content to it:
upstream mastodon {
server localhost:3000;
}
server {
listen 80;
server_name mastodon.example.com;
location / {
proxy_set_header Host $