Mastodon インストール · 8 min read · Oct 13, 2025
Ubuntu 22.04にMastodonソーシャルネットワークをインストールする方法

Mastodonは、自己ホスト型ソーシャルネットワーキングサービスを運営するための無料でオープンソースのソフトウェアです。Mastodonを使用すると、他のユーザーをフォローし、メッセージや画像を投稿することができるマイクロブログ機能を提供します。RubyとJavaScriptで書かれており、音声、動画、画像の投稿、アクセシビリティの説明、投票、コンテンツ警告、アニメーションアバター、カスタム絵文字などをサポートしています。Mastodonは、AndroidやiOSなどのさまざまなプラットフォーム用のアプリケーションを提供しています。
このチュートリアルでは、Ubuntu 22.04にMastodonをインストールする方法を示します。
*更新: このガイドは、インストールを明確にし、コメントで言及された問題を修正するために2022年11月30日に更新され、再テストされました。ガイドが書かれて以来、一部のソフトウェアのバージョンが変更されました。*
Dockerを使用してUbuntuにMastodonをインストールするための代替インストールガイドもこちらにあります。
前提条件
- Ubuntu 22.04を実行しているサーバー。
- サーバーにルートパスワードが設定されています。
- 有効なドメイン名がサーバーのIPアドレスを指しています。
始めに
まず、システムパッケージを最新バージョンに更新することをお勧めします。次のコマンドを実行することで行えます:
apt update -y
apt upgrade -yシステムを更新した後、Mastodonに必要な依存関係をいくつかインストールする必要があります。次のコマンドを使用してすべてをインストールできます:
apt install git software-properties-common make apt-transport-https redis-server optipng pngquant jhead jpegoptim gifsicle imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file g++ libprotobuf-dev protobuf-compiler pkg-config gcc autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev libidn11-dev libicu-dev libjemalloc-dev -yすべての依存関係がインストールされたら、次のステップに進むことができます。
Node.jsのインストール
Mastodonは、システムにNode.jsがインストールされていることを必要とします。Node.jsをインストールするには、次のコマンドを使用してNode.jsリポジトリをサーバーに追加します:
curl -sL https://deb.nodesource.com/setup_16.x | bash -リポジトリが追加されたら、次のコマンドを使用してNode.jsバージョン16をインストールします:
apt install nodejs -y次に、YarnのGPGキーをダウンロードして追加し、次のコマンドでリポジトリを有効にします:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list追加が完了したら、次のコマンドでリポジトリを更新し、Yarnをインストールします:
apt update -y
apt -y install yarn完了したら、次のステップに進むことができます。
PostgreSQLのインストールと設定
Mastodonは、データベースバックエンドとしてPostgreSQLを使用します。次のコマンドを使用して最新バージョンのPostgreSQLをインストールできます:
apt install -y postgresql postgresql-contribPostgreSQLをインストールした後、次のコマンドを使用してPostgreSQLサービスを開始します:
systemctl start postgresql次に、PostgreSQLシェルにログインします:
sudo -u postgres -i psql次に、Mastodon用のデータベースを作成します:
CREATE DATABASE mastodon;次に、次のコマンドを使用してデータベースユーザーを作成します:
CREATE USER mastodon;次に、次のコマンドを使用してMastodonユーザーのパスワードを設定します:
ALTER USER mastodon WITH ENCRYPTED PASSWORD 'password';次に、データベースを作成するための適切な権限を設定します:
ALTER USER mastodon createdb;次に、このユーザーをMastodonデータベースの所有者として設定します:
ALTER DATABASE mastodon OWNER TO mastodon;最後に、次のコマンドを使用してPostgreSQLシェルから退出します:
\qRubyのインストール
Mastodonは、サーバーにRubyバージョン2.5以上がインストールされていることも必要とします。インストールされていない場合は、次のコマンドを使用してインストールできます:
apt install -y ruby ruby-devインストール後、次のコマンドを使用してRubyのバージョンを確認できます:
ruby -v次の出力でRubyのバージョンが表示されます:
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu]Mastodonのインストールと設定
次に、Mastodonを実行するための専用ユーザーを作成する必要があります。次のコマンドを使用して作成できます:
adduser mastodon --system --group --disabled-login次に、GitリポジトリからMastodonの最新バージョンをダウンロードします:
git clone https://github.com/tootsuite/mastodon.git次に、Mastodon用の/var/www/ディレクトリを作成します(存在しない場合)。
mkdir -p /var/www/次に、Mastodonディレクトリを/var/wwwディレクトリに移動します:
mv mastodon/ /var/www/次に、Mastodonディレクトリの所有権をmastodonに変更します:
chown -R mastodon:mastodon /var/www/mastodon/次に、/var/www/mastodonディレクトリに移動し、最新のブランチをチェックアウトします:
cd /var/www/mastodon/
sudo -u mastodon git checkout v4.0.2次の出力が得られます:
Note: switching to 'v4.0.2'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 03b0f3ac8 Bump version to 4.0.2 (#20725)次に、次のコマンドを使用してMastodonに必要なすべての依存関係をインストールします:
gem install bundler
sudo -u mastodon bundle config deployment 'true'
sudo -u mastodon bundle config without 'development test'
sudo -u mastodon bundle install -j$(getconf _NPROCESSORS_ONLN)最後に、次のコマンドを使用してMastodonセットアップウィザードを実行します:
sudo -u mastodon RAILS_ENV=production bundle exec rake mastodon:setupドメイン名を提供するように求められます:
Type application/netcdf is already registered as a variant of application/netcdf.
Your instance is identified by its domain name. Changing it afterward will break things.
Domain name: mastodon.linuxbuz.comドメイン名を入力し、Enterキーを押します。シングルユーザーモードを有効にするかどうかを尋ねられます:
Single user mode disables registrations and redirects the landing page to your public profile.
Do you want to enable single user mode? NoNoと入力し、Enterキーを押します。Mastodonを実行するためにDockerを使用するかどうかを尋ねられます:
Are you using Docker to run Mastodon? nonoと入力し、Enterキーを押します。PostgreSQLデータベースの詳細を提供するように求められます:
PostgreSQL host: /var/run/postgresql
PostgreSQL port: 5432
Name of PostgreSQL database: mastodon
Name of PostgreSQL user: mastodon
Password of PostgreSQL user: PostgreSQLデータベースの詳細を提供し、Enterキーを押します。Redisサーバーの詳細を提供するように求められます:
Database configuration works! ????
Redis host: localhost
Redis port: 6379
Redis password: Redisホスト、ポートを提供し、パスワードフィールドを空のままにしてEnterキーを押します。クラウドにファイルを保存するかどうかを尋ねられます:
Redis configuration works! ????
Do you want to store uploaded files on the cloud? NoNoと入力し、Enterキーを押します。localhostからメールを送信するかどうかを尋ねられます:
Do you want to send e-mails from localhost? yes
E-mail address to send e-mails "from": Mastodon <[email protected]>
Send a test e-mail with this configuration right now? no必要なすべての詳細を提供し、Enterキーを押します。すべての設定を保存するかどうかを尋ねられます:
This configuration will be written to .env.production
Save configuration? (Y/n) YYと入力し、Enterキーを押します。データベースを準備するかどうかを尋ねられます:
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? (Y/n) YYと入力し、Enterキーを押します。CSS/JSアセットをコンパイルするかどうかを尋ねられます。
The final step is compiling CSS/JS assets.
This may take a while and consume a lot of RAM.
Compile the assets now? (Y/n) YYと入力し、Enterキーを押します。管理者パスワードを設定するかどうかを尋ねられます:
All done! You can now power on the Mastodon server ????
Do you want to create an admin user straight away? Yes
Username: admin
E-mail: [email protected]
You can login with the password: 9835fbd5e569ad149610862178580da7**
You can change your password once you login.管理者のユーザー名とメールアドレスを提供し、インストールを完了するためにEnterキーを押します。
Mastodon用のSystemdサービスファイルを作成
Mastodonには、Mastodonサービスを管理するための事前設定されたsystemdファイルが付属しています。これらを/etc/systemd/system/ディレクトリにコピーする必要があります。
cp /var/www/mastodon/dist/mastodon*.service /etc/systemd/system/次に、サービスファイル内のMastodon作業ディレクトリを/home/mastodon/live/から/var/www/mastodon/に変更する必要があります。次のコマンドで行えます:
sed -i 's/home\/mastodon\/live/var\/www\/mastodon/g' /etc/systemd/system/mastodon-*.serviceサービスファイル内の/home/mastodon/.rbenv/shims/bundleを/usr/local/bin/bundleに変更する必要があります:
sed -i 's/home\/mastodon\/.rbenv\/shims/usr\/local\/bin/g' /etc/systemd/system/mastodon-*.service次に、設定変更を適用するためにsystemdを再読み込みします:
systemctl daemon-reload次に、すべてのMastodonサービスを開始し、有効にします:
systemctl enable --now mastodon-web mastodon-sidekiq mastodon-streaming次のコマンドを使用してすべてのサービスの状態を確認できます:
systemctl status mastodon-web mastodon-sidekiq mastodon-streaming出力:
? mastodon-web.service - mastodon-web
Loaded: loaded (/etc/systemd/system/mastodon-web.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-11-30 03:07:13 UTC; 19s ago
Main PID: 10201 (ruby3.0)
Tasks: 29 (limit: 464140)
Memory: 249.0M
CGroup: /system.slice/mastodon-web.service
??10201 "puma 5.6.5 (tcp://127.0.0.1:3000) [mastodon]" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
??10228 "puma: cluster worker 0: 10201 [mastodon]" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
??10232 "puma: cluster worker 1: 10201 [mastodon]" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
Nov 30 03:07:15 ubuntu22042 bundle[10201]: [10201] * Max threads: 5
Nov 30 03:07:15 ubuntu22042 bundle[10201]: [10201] * Environment: production
Nov 30 03:07:15 ubuntu22042 bundle[10201]: [10201] * Master PID: 10201
Nov 30 03:07:15 ubuntu22042 bundle[10201]: [10201] * Workers: 2
Nov 30 03:07:15 ubuntu22042 bundle[10201]: [10201] * Restarts: (?) hot (?) phased
Nov 30 03:07:15 ubuntu22042 bundle[10201]: [10201] * Preloading application
Nov 30 03:07:27 ubuntu22042 bundle[10201]: [10201] * Listening on http://127.0.0.1:3000
Nov 30 03:07:27 ubuntu22042 bundle[10201]: [10201] Use Ctrl-C to stop
Nov 30 03:07:27 ubuntu22042 bundle[10201]: [10201] - Worker 0 (PID: 10228) booted in 0.04s, phase: 0
Nov 30 03:07:27 ubuntu22042 bundle[10201]: [10201] - Worker 1 (PID: 10232) booted in 0.01s, phase: 0
? mastodon-sidekiq.service - mastodon-sidekiq
Loaded: loaded (/etc/systemd/system/mastodon-sidekiq.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-11-30 03:07:13 UTC; 19s ago
Main PID: 10199 (ruby3.0)
Tasks: 32 (limit: 464140)
Memory: 247.1M
CGroup: /system.slice/mastodon-sidekiq.service
??10199 "sidekiq 6.5.7 mastodon [0 of 25 busy]" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
Nov 30 03:07:29 ubuntu22042 bundle[10199]: 2022-11-30T03:07:29.202Z pid=10199 tid=cc7 uniquejobs=upgrade_locks INFO: Start - Converting v6 lo>
Nov 30 03:07:29 ubuntu22042 bundle[10199]: 2022-11-30T03:07:29.202Z pid=10199 tid=cc7 uniquejobs=upgrade_locks INFO: Done - Converting v6 loc>
Nov 30 03:07:29 ubuntu22042 bundle[10199]: 2022-11-30T03:07:29.202Z pid=10199 tid=cc7 uniquejobs=upgrade_locks INFO: Start - Deleting v6 keys
Nov 30 03:07:29 ubuntu22042 bundle[10199]: 2022-11-30T03:07:29.203Z pid=10199 tid=cc7 uniquejobs=upgrade_locks INFO: Done - Deleting v6 keys
デフォルトでは、Mastodonはポート3000でリッスンします。次のコマンドを使用して確認できます:
ss -lnpt | grep 3000出力:
LISTEN 0 1024 127.0.0.1:3000 0.0.0.0:* users:(("ruby3.0",pid=10232,fd=5),("ruby3.0",pid=10228,fd=5),("ruby3.0",pid=10201,fd=5))Nginxをリバースプロキシとして設定
まず、次のコマンドを使用してNginxウェブサーバーパッケージをインストールします:
apt install nginx -y次に、NginxディレクトリにNginx仮想ホスト設定ファイルをコピーします:
cp /var/www/mastodon/dist/nginx.conf /etc/nginx/conf.d/mastodon.conf次に、Mastodon仮想ホスト設定ファイルを編集します:
nano /etc/nginx/conf.d/mastodon.confポート80のサーバーブロックとポート443のサーバーブロックの両方で、次の行を見つけます:
server_name example.com;これを次の行に置き換えます:
server_name mastodon.linuxbuz.com;ポート80のサーバーブロックとポート443のサーバーブロックの両方で、次の行を見つけます。
root /home/mastodon/live/public;これを次の行に置き換えます:
root /var/www/mastodon/public;次の2行を見つけます。
# ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;これを次のように変更し、Nginxが一時的に自己署名TLS証明書を使用するようにします。後で有効なLet’s Encrypt証明書を取得します。
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;ファイルを保存して閉じたら、Nginx用のキャッシュディレクトリを作成します:
mkdir -p /var/nginx/cache/次に、Nginxの構文エラーを確認します:
nginx -t次の出力が得られます:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful次に、変更を適用するためにNginxサービスを再起動します:
systemctl restart nginxLet’s Encrypt SSLでMastodonを保護
MastodonウェブサイトでHTTPSを有効にするには、サーバーにCertbotパッケージをインストールする必要があります。
まず、次のコマンドを使用してSnapパッケージマネージャーをインストールします:
apt install snapd次に、Snapパッケージを最新バージョンに更新します:
snap install core
snap refresh core次に、次のコマンドを使用してCertbotパッケージをインストールします:
snap install --classic certbot次に、Certbotバイナリのシンボリックリンクをシステムの場所に作成します:
ln -s /snap/bin/certbot /usr/bin/certbot次に、次のコマンドを実行してLet’s Encrypt SSL証明書をダウンロードしてインストールします:
certbot --nginx -d mastodon.linuxbuz.comメールアドレスを提供し、サービス利用規約に同意するように求められます:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): [email protected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: YYと入力し、Enterキーを押して、ドメインのSSL証明書をダウンロードしてインストールします:
Account registered.
Requesting a certificate for mastodon.linuxbuz.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/mastodon.linuxbuz.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/mastodon.linuxbuz.com/privkey.pem
This certificate expires on 2023-02-28.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
Deploying certificate
Successfully deployed certificate for mastodon.linuxbuz.com to /etc/nginx/conf.d/mastodon.conf
Congratulations! You have successfully enabled HTTPS on https://mastodon.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
* Donating to EFF: https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Mastodonウェブインターフェースにアクセス
今、ウェブブラウザを開き、URL https://mastodon.linuxbuz.comを入力します。次のページにリダイレクトされます:

サインインボタンをクリックします。Mastodonのログインページが表示されるはずです:

今、先ほど作成した管理者のメールアドレスとパスワードを提供し、ログインボタンをクリックします。次のページにMastodonダッシュボードが表示されるはずです:

おめでとうございます!Ubuntu 22.04サーバーにMastodonを正常にインストールして設定しました。これで、Mastodonを使用して独自のソーシャルメディアネットワークを簡単に作成できます。質問があればお気軽にお尋ねください。
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。