How to upgrade an instance to Mastodon 4.2

Posted by:

  • Avatar of Konstantin

    Konstantin

Let's upgrade a Mastodon instance to the latest version (without Docker)

The Mastodon documentation contains an excellent overview of the upgrade process. Based on that, you can come up with the list of commands necessary to carry out an upgrade.

Don't forget to back-up before going any further!

The upgrade process described bellow will result in instance downtime. If others are also using it, make sure to make them aware that the app will be temporarily unavailable.

Upgrading to Mastodon 4.2

Connect to your server using SSH

Our first step is to shut down the currently running instance.

systemctl stop mastodon-*

Then, we switch to the default mastodon user and navigate to mastodon root directory (the /live folder)

su - mastodon -s /bin/bash
cd ~/live

Install the new version

First, we need to download the new version and make sure the correct local Ruby version is installed. In this case, that's 3.2.2 and we're using rbenv:

git fetch
git checkout v4.2.0
rbenv install $(cat .ruby-version) --verbose

Let's upgrade Mastodon

bundle install
RAILS_ENV=production bundle exec rails db:migrate
rm -rf node_modules && yarn install
yarn build:production
RAILS_ENV=production bundle exec rails assets:precompile

Starting the updated instance

Finally, we need to start all Mastodon services. Use the exit command to exit the mastodon user session and go back to the system user. Then run the following:

sudo systemctl restart mastodon-sidekiq.service

sudo systemctl restart mastodon-web.service

sudo systemctl restart mastodon-streaming.service

And voilà 🎉! You should be able to access your instance.

One more thing...

If you're building a Mastodon app using Swift, feel free to check out TootSDK - a cross-platform Swift library for the Mastodon and the fediverse. It supports Mastodon, Akkoma/Pleroma, PixelFed and others.

Mastodon TootSDK

Tags