How To

Install Mastodon 5.0 on Ubuntu 26.04/24.04 with Let’s Encrypt SSL

Mastodon 5.0 raised the floor under every self-hosted server: Ruby 4.0, Node.js 24, Redis 7.2 and nginx syntax that the nginx packaged in Ubuntu 24.04 does not understand. If you install Mastodon on Ubuntu by following an older guide, the build either refuses to start or nginx refuses the vhost, and neither error tells you why.

Original content from computingforgeeks.com - post 29852

This guide builds a single-server instance from source with PostgreSQL, Redis, nginx and a Let’s Encrypt certificate, then upgrades a running 4.7 server to 5.0 the zero-downtime way. The HTTP-01 install path, the upgrade and every output below come from three fresh servers we ran on Ubuntu 26.04 and 24.04 in December 2026, and the two places where 24.04 needs extra work are called out where they bite.

Check what Mastodon 5.0 needs

The Mastodon 5.0 release notes drop Ruby 3.3 and 3.4 and Node.js 22, and they set new minimums for the database, cache and media tools. Ubuntu’s own archive covers some of these and misses others, so the table compares the requirement with what each release ships and what we ended up running.

ComponentMastodon 5.0 needsUbuntu 26.04Ubuntu 24.04
Ruby4.0rbenv build (4.0.10)rbenv build (4.0.10)
Node.js24+Archive has 22, use NodeSource 24Archive has 18, use NodeSource 24
PostgreSQL14+PGDG repo (19.0)PGDG repo (19.0)
Redis7.2+Archive 8.0.5, fineArchive 7.0.15, too old
nginxhttp2 on; needs 1.25.1+Archive 1.28.3, fineArchive 1.24.0, needs an edit
libvips8.13+8.18.08.15.1
FFmpeg5.1+8.0.16.1.1

Ubuntu 26.04 is the easier target because its archive already carries a new enough Redis and nginx. On 24.04 you will replace Redis with the packages.redis.io build and rewrite two listen lines in the nginx vhost, both shown below. If you’re still deciding between the two releases for a new box, our Ubuntu 26.04 vs 24.04 comparison covers the rest of the differences.

Prerequisites

Everything runs on one server: nginx is the only process facing the internet, and Puma, the streaming API, Sidekiq, PostgreSQL and Redis all listen on 127.0.0.1. That layout matters because none of the backends has its own TLS or authentication worth exposing, so the firewall only ever needs ports 80 and 443 open. The diagram shows how the pieces talk to each other once the install is finished.

Mastodon architecture on one Ubuntu server: nginx in front of mastodon-web, mastodon-streaming and sidekiq, with PostgreSQL and Redis on localhost

Before you start, have these ready:

  • Ubuntu 26.04 or 24.04 server with a sudo user
  • A domain or subdomain with an A record pointing at the server (any DNS provider)
  • Ports 80 and 443 open in the cloud firewall or router
  • SMTP credentials from a mail provider, unless you can live without signup and reset mail at first

Our lab servers had 4 vCPUs and 15 GiB of RAM. A fresh instance with one account used 1.5 to 1.7 GiB of memory, a 15 MB database and 1.7 to 1.8 GB for the application directory, so those numbers are a floor rather than a target. Size the production box from what will actually grow: active users, how many remote servers you federate with (Sidekiq queues and the media cache grow with them), and whether you keep media on local disk or push it to object storage. Plan for 4 GB of RAM and 40 GB of disk as the minimum for a small community instance, and add memory before you add users, because compiling Ruby and the web assets is the hungriest thing you’ll do on it. A low-cost VM works for a personal server; our roundup of cheap VPS providers lists the ones worth a look.

Set the domain variable

The domain shows up in the certificate request, the nginx vhost and the checks at the end, so export it once in your sudo user’s shell and paste the rest as written:

export SITE_DOMAIN="social.example.com"

Pick this name carefully. Mastodon bakes the domain into every account and post it federates, and the setup wizard itself warns that changing it afterwards breaks things. The variable lives only in this shell, so export it again if you log out before the nginx step.

Add the Node.js and PostgreSQL repositories

The Node.js in the Ubuntu archive is 22 on 26.04 and 18 on 24.04, and the package.json in Mastodon 5.0 refuses anything below 24. The NodeSource node_24.x repository fixes that, and the PGDG repository gives you a current PostgreSQL instead of whatever the release froze. Both repos have to be in place before the big package install, because apt would otherwise pull the archive Node.js and you would find out only when Yarn refuses to run. Install the tools the repository setup needs first:

sudo apt update
sudo apt install -y curl wget gnupg apt-transport-https lsb-release ca-certificates jq

Add the NodeSource key and repository:

sudo install -d /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

Then the PostgreSQL one. The $(lsb_release -cs) part picks the right suite for 26.04 or 24.04 on its own:

sudo wget -O /usr/share/keyrings/postgresql.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc
echo "deb [signed-by=/usr/share/keyrings/postgresql.asc] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql.list

Be aware that the unversioned postgresql package from PGDG now pulls PostgreSQL 19. Mastodon 5.0 ran on it without complaint on all three servers. If you’d rather stay on a release your other tooling already knows, install postgresql-18 in the next step instead of postgresql. The Node.js 24 on Ubuntu guide has more on the NodeSource repo if you run other Node apps on the same host.

Install the system packages

One install pulls the build toolchain Ruby needs, the media tools Mastodon shells out to, and the services it runs on. This is the package list from the official install docs, unchanged, so a later doc update is easy to diff against. The libjemalloc-dev package is the one people drop by accident, and without it the Ruby build further down fails at configure time:

sudo apt update
sudo apt install -y \
  imagemagick ffmpeg libvips-tools libpq-dev libxslt1-dev file git \
  protobuf-compiler pkg-config autoconf bison build-essential \
  libssl-dev libyaml-dev libreadline-dev zlib1g-dev libffi-dev libgdbm-dev \
  nginx nodejs redis-server postgresql certbot python3-certbot-nginx \
  libidn-dev libicu-dev libjemalloc-dev

Yarn comes through Corepack, which ships with Node.js 24 but is off by default. Turn it on so the yarn command resolves to the version pinned in Mastodon’s package.json:

sudo corepack enable

On Ubuntu 26.04 that is the whole dependency story, because the archive Redis is already 8.0.5. On 24.04 there is one more package to replace before you go further, so do it now rather than after Mastodon is running on top of it.

Replace Redis on Ubuntu 24.04

Ubuntu 24.04 ships Redis 7.0.15, under the 7.2 minimum in the release notes. Our 24.04 install didn’t crash on it, but running below a stated minimum is how you end up debugging a queue problem six months from now, so we moved the server to the Redis-maintained repository described in the Redis apt install docs:

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt update
sudo apt install -y -o Dpkg::Options::=--force-confold redis redis-server redis-tools

The --force-confold option keeps your existing /etc/redis/redis.conf if you’ve edited it, so a tuned config isn’t silently replaced. Make sure the service is enabled and running, then confirm the new version and that the server still answers:

sudo systemctl enable --now redis-server
redis-cli ping
redis-cli info server | grep -E "redis_version|config_file"

You want PONG and a version of 7.2 or newer. Ours moved from 7.0.15 to 8.12.0. Because Ubuntu’s stock redis.conf was unedited, dpkg swapped in the Redis package’s own file at the same path:

Replacing Ubuntu 24.04 Redis 7.0.15 with Redis 8.12.0 from packages.redis.io for Mastodon

Redis 8 binds to localhost by default here, which is what Mastodon expects. If you run an exposed Redis anywhere else, read our Redis CVE-2025-49844 check before you trust an old build.

Create the mastodon user and database role

Mastodon runs as its own unprivileged user, with Ruby installed in that user’s home rather than system-wide. Keeping it apart means a compromised web process can read the app and its config, but not your sudo account or other services. Create the account without a password, since you only ever reach it through sudo:

sudo adduser --disabled-password --gecos "" mastodon

Then give it a PostgreSQL role with the right to create its own database. Mastodon connects over the local Unix socket with peer authentication, so the role needs no password:

sudo -u postgres psql -c "CREATE USER mastodon CREATEDB;"

PostgreSQL answers with CREATE ROLE. The wizard creates mastodon_production itself later, which is why the role gets CREATEDB instead of you creating the database by hand.

Build Ruby 4.0 with rbenv

Neither Ubuntu release packages Ruby 4.0, and Mastodon pins an exact patch release in .ruby-version anyway, so rbenv builds it from source. Switch to the mastodon user for this and the next two sections:

sudo -iu mastodon

Install rbenv and the ruby-build plugin, and load rbenv into the shell:

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

Clone Mastodon next, because the Ruby version to build comes from the repository. The tag filter skips release candidates and picks the newest stable tag, which was v5.0.0 at the time of writing:

git clone https://github.com/mastodon/mastodon.git live && cd live
git checkout $(git tag -l | grep '^v[0-9.]*$' | sort -V | tail -n 1)
cat .ruby-version

Git reports HEAD is now at 0406ba23be Bump version to v5.0.0, and .ruby-version reads 4.0.10. Now build that Ruby with jemalloc, which keeps Puma and Sidekiq memory from creeping over days of uptime:

RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install

This is the slow step. It took about six minutes on 4 vCPUs on both releases (we wrapped it in time), and it finishes like this:

==> Installing ruby-4.0.10...
-> ./configure "--prefix=$HOME/.rbenv/versions/4.0.10" --enable-shared --with-ext=openssl,psych,+ --with-jemalloc
-> make -j 4
-> make install
==> Installed ruby-4.0.10 to /home/mastodon/.rbenv/versions/4.0.10

real	6m8.849s

A system-wide Ruby install on Ubuntu is a different job. Keep this one private to the mastodon user, so an apt upgrade can never swap the interpreter under a running instance. It also means each Mastodon upgrade that bumps .ruby-version builds the new Ruby next to the old one, and you can roll back by checking out the previous tag.

Install the Ruby and JavaScript dependencies

Still inside ~/live as the mastodon user, tell Bundler to install for production only, then pull the gems and the JavaScript packages:

bundle config deployment 'true'
bundle config without 'development test'
bundle install -j$(getconf _NPROCESSORS_ONLN)
yarn install

Bundler prints a deprecation notice about bundle config without a subcommand; the docs still use this form and it works. The gem install ends on this line after about 85 seconds, and Yarn takes another 25 to 30:

Bundle complete! 155 Gemfile dependencies, 279 gems now installed.

The release notes warn that charlock_holmes can fail to compile on newer GCC and suggest BUNDLE_BUILD__CHARLOCK_HOLMES="--with-cxxflags=-std=c++17". We did not need it, because the gem built cleanly with GCC 15.2 on 26.04 and GCC 13.3 on 24.04. Keep the flag in mind only if bundle install stops on that gem, and set it as an environment variable for that one run so it does not linger in your Bundler config.

Run the Mastodon setup wizard

The wizard writes .env.production, creates and loads the database and compiles the web assets in one pass. Start it from ~/live:

RAILS_ENV=production bin/rails mastodon:setup

Most prompts have the right default for a single-server install. These are the answers we gave and why:

PromptAnswerWhy
Domain nameyour SITE_DOMAINPermanent, part of every account handle
Single user modeNoYes only for a one-person instance
Using DockerNoThis is a source install
PostgreSQL host, port, database, userEnter on each defaultSocket /var/run/postgresql, peer auth
PostgreSQL passwordEnter (blank)Peer auth needs none
Redis host, port, passwordEnter on each defaultlocalhost:6379, no password
Store files on the cloudNoSwitch to S3 later if media grows
Send e-mails from localhostNoUse your provider’s SMTP
SMTP server, port, user, passwordYour provider’s valuesSignups and resets need it
Send a test e-mailYes, with real SMTPCatches bad credentials now
No SMTP yetDefaults, authentication none, No to the testWhat we did in the lab; add SMTP later
Check for important updatesYesSecurity notices in the admin UI
Save, prepare database, compile assetsYes, Yes, YesWrites config, loads schema, builds UI
Create an admin userNoWe do it with tootctl below

Both database and Redis checks print a “configuration works!” line before the wizard moves on, so a wrong answer fails right there instead of at startup. The end of a clean run looks like this, and the whole wizard took about a minute on our servers:

Now that configuration is saved, the database schema must be loaded.
If the database already exists, this will erase its contents.
Prepare the database now? Yes
Running `RAILS_ENV=production rails db:setup` ...

Created database 'mastodon_production'
Done!

The final step is compiling CSS/JS assets.
Done!

All done! You can now power on the Mastodon server 🐘

Leave the mastodon user’s shell with exit, because the certificate, nginx and systemd steps need root. If the wizard crashed for you on the SMTP questions instead, the troubleshooting section near the end has the two errors we hit and what causes them. Our first run died exactly there, so it is worth reading before you start the wizard rather than after.

Get a Let’s Encrypt certificate

Mastodon’s shipped nginx vhost already contains the HTTPS server block and the HTTP redirect, so you only want certbot to fetch the certificate, not to rewrite any config. That’s what certonly --nginx does: it answers the HTTP-01 challenge through the default nginx site, which still owns port 80 at this point:

sudo certbot certonly --nginx -d "${SITE_DOMAIN}" --register-unsafely-without-email --agree-tos -n

Swap --register-unsafely-without-email for -m [email protected] if you want the ACME account tied to an address. Look for the certificate path and the expiry date in the output, then prove renewal works before you forget about it:

sudo certbot renew --dry-run

Both runs succeeded on all three servers, with certificates valid until March 2027 and the renewal timer installed by the certbot package:

certbot issuing a Let's Encrypt certificate for the Mastodon domain and a successful renewal dry run

If certbot fails with a connection or timeout error, port 80 is not reaching the server or the A record is not live yet. Check both before retrying, because Let’s Encrypt rate-limits repeated failures for the same name. A dig +short on the domain from another machine and a curl -I http:// to it settle both questions in a few seconds.

Use DNS-01 when port 80 is closed

A server behind NAT, or one you don’t want reachable on port 80, can prove ownership through a DNS TXT record instead. Certbot has a plugin per DNS provider:

DNS providerUbuntu package
Cloudflarepython3-certbot-dns-cloudflare
Amazon Route 53python3-certbot-dns-route53
DigitalOceanpython3-certbot-dns-digitalocean
Google Cloud DNSpython3-certbot-dns-google
Linodepython3-certbot-dns-linode
OVHpython3-certbot-dns-ovh
BIND or any RFC 2136 serverpython3-certbot-dns-rfc2136

With Cloudflare as the example, create an API token scoped to Zone:DNS:Edit for that zone, then open a credentials file that only root can read:

sudo install -d -m 700 /root/.secrets
sudo vim /root/.secrets/cloudflare.ini

Put the token on a single line in the file:

dns_cloudflare_api_token = your-cloudflare-api-token

Lock the file to mode 600, or certbot warns that other users can read it, then request the certificate with the plugin. Substitute your provider’s plugin and credentials file if you’re elsewhere:

sudo chmod 600 /root/.secrets/cloudflare.ini

Then install the plugin and issue the certificate. Unlike the nginx authenticator, certonly with a DNS plugin never touches nginx, so the --deploy-hook reloads it after every renewal. Without it nginx keeps serving the old certificate from memory until it expires:

sudo apt install -y python3-certbot-dns-cloudflare
sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials /root/.secrets/cloudflare.ini -d "${SITE_DOMAIN}" --agree-tos -m [email protected] -n --deploy-hook "systemctl reload nginx"

The certificate lands in the same /etc/letsencrypt/live/ path, so the nginx step that follows doesn’t change. A DNS-01 failure is almost always the token: wrong zone, read-only scope, or a file permission certbot rejects.

Configure nginx for Mastodon

Mastodon ships a ready vhost in dist/nginx.conf. Copy it in, put your domain in place of example.com, and uncomment the two certificate lines that point at the Let’s Encrypt files:

sudo cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon
sudo sed -i "s/example.com/${SITE_DOMAIN}/g" /etc/nginx/sites-available/mastodon
sudo sed -i 's|# ssl_certificate|ssl_certificate|' /etc/nginx/sites-available/mastodon
sudo ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon
sudo rm /etc/nginx/sites-enabled/default

nginx serves the compiled assets straight from /home/mastodon/live/public, and Ubuntu creates home directories as 750, so nginx needs the execute bit for other users to pass through to the assets. We ran this before reloading nginx with the Mastodon vhost on every server:

sudo chmod o+x /home/mastodon

Test the config and reload:

sudo nginx -t && sudo systemctl reload nginx

On Ubuntu 26.04 this prints syntax is ok and test is successful, and you can move on to the services. On 24.04 it fails, which is the next fix.

Fix “unknown directive http2” on Ubuntu 24.04

The 5.0 vhost moved to the standalone http2 on; directive, which nginx only understands from 1.25.1. Ubuntu 24.04 ships 1.24.0, so the test stops on line 36 of the file:

2026/12/04 20:30:34 [emerg] 31613#31613: unknown directive "http2" in /etc/nginx/sites-enabled/mastodon:36
nginx: configuration file /etc/nginx/nginx.conf test failed

Put HTTP/2 back on the listen lines, the syntax 1.24 does know, and delete the new directive. This is the only difference between the 4.7 and 5.0 vhosts, so nothing else in the file needs touching:

sudo sed -i -e "s/^  listen 443 ssl;/  listen 443 ssl http2;/" -e "s/^  listen \[::\]:443 ssl;/  listen [::]:443 ssl http2;/" -e "/^  http2 on;/d" /etc/nginx/sites-available/mastodon
sudo nginx -t && sudo systemctl reload nginx

The test passes and the site answers over HTTP/2, exactly as on 26.04:

nginx -t failing with unknown directive http2 on Ubuntu 24.04 and passing after the listen lines are rewritten

Remember this edit when you upgrade Mastodon later, because copying a fresh dist/nginx.conf over the old vhost brings the directive back and nginx refuses to reload until you redo it.

Start the Mastodon services

Three systemd units run the instance: mastodon-web (Puma), mastodon-sidekiq (background jobs) and mastodon-streaming (real-time updates). Copy the shipped units and start them:

sudo cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now mastodon-web mastodon-sidekiq mastodon-streaming

Give them 15 seconds, then check the state and ask the instance API which version it’s running:

systemctl status mastodon-web mastodon-sidekiq mastodon-streaming --no-pager | grep -E "●|Active:"
curl -s https://${SITE_DOMAIN}/api/v2/instance | jq '{domain, version}'

Web and Sidekiq show active (running). Streaming shows active (exited), which looks wrong but isn’t: it’s a oneshot unit that starts [email protected], and that instance is the one actually running Node.js on port 4000:

systemctl status showing mastodon-web, mastodon-sidekiq and mastodon-streaming active, and the instance API reporting version 5.0.0

A quick sudo ss -tlnp should show Puma on 127.0.0.1:3000, streaming on 127.0.0.1:4000, PostgreSQL on 5432 and Redis on 6379, all loopback, with only nginx on 80 and 443. The full toolchain on the 26.04 server, for reference:

Ruby, Node.js, Yarn, PostgreSQL, Redis, nginx, libvips and FFmpeg versions on the Ubuntu 26.04 Mastodon server

If any port is missing, journalctl -u mastodon-web -n 50 (or the unit that is down) shows why before you go hunting in nginx. A 502 in the browser with both ports present usually means nginx came up before Puma finished booting, so wait a few seconds and reload.

Create the owner account

We skipped the admin prompt in the wizard because tootctl does it better: it lets you confirm and approve the account in the same command, so you don’t need working mail for your first login. Run it as the mastodon user, with your own username and a real mailbox:

sudo -iu mastodon

Then, from that shell:

cd ~/live
RAILS_ENV=production bin/tootctl accounts create josphat --email [email protected] --confirmed --approve --role Owner

The command prints OK and a generated password. Copy it now, because it isn’t shown again:

OK
New password: 4f1c9a7e2b8d06c35e7a91f0d2b46c18

The email has to be on a domain with working MX records. Mastodon checks that before it creates the account, so [email protected] or any other placeholder fails with “email unreachable”, covered in the troubleshooting section. The --approve flag matters too, because an instance that requires approval would otherwise park even the owner in the pending queue.

Log in and try the new web UI

Open https://social.example.com with your own domain and sign in with the owner email and the generated password. The login page loads over HTTPS with the certificate from earlier:

Mastodon 5.0 login page served over HTTPS on a fresh Ubuntu install

Change the generated password first: open Preferences, then Account in the settings sidebar. Then pick a colour, which 5.0 added to the appearance settings:

  1. Open Appearance in the preferences menu.
  2. Choose one of the five options under Theme color.
  3. Click Save changes at the top right.
Mastodon 5.0 Appearance settings with the new Theme color choice and Save changes button
  1. 1Appearance
  2. 2Theme color
  3. 3Save changes

The Save button sits in the page header, not under the form, which is easy to miss on a wide screen. The composer changed too: New Post now opens a modal instead of the old sidebar box.

  1. Set who sees the post with the Visibility menu, which reads “Public” by default.
  2. The extra settings for the post sit behind the gear icon, labelled Composer options in the figure.
  3. Send it with Publish.
The new Mastodon 5.0 composer modal with the visibility menu and composer options
  1. 1Visibility
  2. 2Composer options
  3. 3Publish

The first post shows up in the home feed straight away, which also proves the streaming API is wired through nginx. If posts only appear after a page refresh, the /api/v1/streaming proxy is not reaching port 4000, so check mastodon-streaming@4000 before anything else:

Mastodon 5.0 home feed with the first post and the Cyan theme color

Before you share the address, open Administration, Server Settings, Registrations and set who may sign up. An open instance with no moderation is the first thing spam bots look for, and approval-only is the safer start for a small community.

Read the Server Health page

System checks no longer sit on the admin dashboard in 5.0. They moved to their own Server Health page under Administration, backed by a new /api/v2/admin/server_checks endpoint you can poll from monitoring:

Mastodon 5.0 Server Health page under Administration with completed checks

Sidekiq runs the checks every 15 minutes (the ServerChecksScheduler entry in config/sidekiq.yml): database schema, Elasticsearch, media privacy, server rules, Sidekiq processes and software version. On a fresh server the only warning is “Set up server rules”, which clears once you add at least one rule. A Sidekiq or schema warning here after an upgrade means a process or a migration didn’t finish, so check this page every time you upgrade.

Upgrade an existing server from 4.7 to 5.0

Mastodon only supports zero-downtime upgrades into 5.0 from the 4.7 line, and the update steps assume 4.7.6 or later. Older servers should step through 4.7 first. We upgraded a 4.7.7 instance on Ubuntu 24.04 with this sequence. Before touching code on 24.04, replace Redis as shown earlier, because 5.0’s 7.2 floor applies to upgrades too. A 4.7 server still on Node.js 22 also needs the NodeSource 24 repository from the install section first, because 5.0’s yarn install won’t run on 22. Then, as the mastodon user in ~/live, take a database dump you can restore from:

pg_dump -Fc mastodon_production > ~/mastodon-pre-5.0.dump

Our one-account test database dumped to 839K. A real instance takes much longer, so plan the window around it, and copy the dump off the server before you continue. Fetch the new tag and update ruby-build so rbenv knows the Ruby version 5.0 pins. 4.7.7 already used Ruby 4.0.10, so --skip-existing returned immediately for us:

git fetch --tags
git checkout v5.0.0
git -C ~/.rbenv/plugins/ruby-build pull
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install --skip-existing

Install the new dependencies, rebuild the assets and run only the pre-deployment migrations, all while the old version keeps serving:

bundle install
yarn install --immutable
RAILS_ENV=production bundle exec rails assets:precompile
SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production bundle exec rails db:migrate

Bundler took 37 seconds, Yarn 23 and the asset build 42. The 18 pre-deployment migrations ran in about 4 seconds, including CreateAdminServerChecks for the new health page. You’ll also see a column of [strong_migrations] DANGER: No lock timeout set lines, which are notices from the migration linter, not failures. Now switch to the new code from your sudo user’s shell:

sudo systemctl reload mastodon-web
sudo systemctl restart mastodon-sidekiq mastodon-streaming

Back as the mastodon user, run the post-deployment migrations, which drop the old columns the 4.7 code still used:

RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bin/tootctl version

Two migrations ran, RemovePrivateKeyFromAccounts and BackfillRelaysAccountId, and the version moved from 4.7.7 to 5.0.0:

Upgrading Mastodon from 4.7.7 to 5.0.0 with pre-deployment and post-deployment database migrations

The systemd units are identical between 4.7.7 and 5.0.0, so there’s nothing to copy there. The shipped nginx vhost only changed its HTTP/2 syntax, and an existing 4.7 vhost already uses the listen ... http2 form that works on every nginx, so leave it alone.

Troubleshoot common install errors

The first four errors are ones we hit across the three servers, with the cause of each. The last is a well-known permissions gotcha that the nginx step above already prevents, listed here because it is the usual cause of a blank page after a hand-built install.

ArgumentError: SMTP-AUTH requested but missing user name

The wizard sends a test mail with whatever you typed, and leaving the SMTP username blank while authentication stays on plain raises this. Either enter real credentials, set authentication to none for an unauthenticated relay, or answer No to the test mail and fix SMTP_LOGIN and SMTP_PASSWORD in .env.production later. Then restart mastodon-web and mastodon-sidekiq so they pick up the change.

LocalJumpError: unexpected return

Right after the failed test mail, the wizard asks whether to try again. Declining crashed mastodon:setup with this error in our run, before it saved anything, so the wizard has to start from the top. Nothing is half-written at that point, which makes it safe to rerun. Answer No to the test mail instead of declining the retry if you don’t have SMTP details yet.

tootctl: Failure/Error: email unreachable

Our first tootctl accounts create with an @example.com address returned exactly this:

Failure/Error: email
    unreachable

Mastodon looks up the MX record of the email domain and refuses one that can’t receive mail. Use an address on a real mail domain; the account is confirmed with --confirmed, so no message actually has to arrive.

nginx: unknown directive “http2”

This is the Ubuntu 24.04 nginx 1.24 problem from the nginx section. Rewrite the two listen 443 lines with http2 and delete http2 on;, or install nginx 1.25.1 or newer from nginx.org’s repository and keep the shipped vhost as it is.

Blank page with 403 on /packs assets

We didn’t hit this one, because the install runs chmod o+x before nginx loads the Mastodon vhost. If you skip that step, nginx cannot traverse /home/mastodon, because Ubuntu creates home directories without the execute bit for other users, and the compiled CSS and JavaScript fail to load. Run sudo chmod o+x /home/mastodon. The directory listing stays private, since nginx only needs to pass through it to reach live/public.

Harden the server for production

The install above is complete and federates, but a public instance needs a few more things before you invite anyone. In the order we’d do them:

  • Firewall that allows only 22, 80 and 443
  • Nightly pg_dump -Fc plus a copy of .env.production, stored off the server
  • Object storage for media once the cache passes a few GB
  • A cron job for media cache cleanup with tootctl media remove
  • Monitoring on /api/v2/admin/server_checks

The backup matters most. .env.production holds the secret keys and VAPID keys, and losing it means every session, push subscription and two-factor setup on the server breaks even if the database survives. Media cache is the thing that fills disks: remote attachments from every server you federate with land in public/system, and on a busy instance that grows by gigabytes a week until the cleanup runs. If you also run a support inbox on the same community, Chatwoot on Ubuntu uses the same Ruby, PostgreSQL and Redis stack, but give it its own server rather than sharing this one.

On a new server, pick Ubuntu 26.04: its archive already meets every 5.0 requirement except Node.js, and the install runs straight through. Ubuntu 24.04 works just as well once Redis and the vhost are fixed, and the full version list for both lives in the official Mastodon install docs.

Keep reading

Upgrade Ubuntu 24.04 to Ubuntu 26.04 LTS (Step by Step) Ubuntu Upgrade Ubuntu 24.04 to Ubuntu 26.04 LTS (Step by Step) UFW Firewall Commands with Examples on Ubuntu 26.04 / 24.04 Security UFW Firewall Commands with Examples on Ubuntu 26.04 / 24.04 Backup and Restore Linux Systems with Timeshift Debian Backup and Restore Linux Systems with Timeshift Build a FHIR MCP Server for MedGemma 2 with Ollama AI Build a FHIR MCP Server for MedGemma 2 with Ollama Run MedGemma 2 Locally with Ollama and FHIR Tool Calling AI Run MedGemma 2 Locally with Ollama and FHIR Tool Calling Install pgvector on PostgreSQL 17 (Rocky Linux 10 / Ubuntu 24.04) AI Install pgvector on PostgreSQL 17 (Rocky Linux 10 / Ubuntu 24.04)

Leave a Comment

Press ESC to close