Gitea インストール · 6 min read · Oct 10, 2025

Ubuntu 22.04にGiteaをインストールする方法

Giteaは、無料でオープンソースの自己ホスト型Gitサービスです。GO言語で書かれており、自分のバージョン管理システムをインターネット上にホストするための簡単な方法を提供します。シンプルで軽量であり、低電力のシステムにインストールできます。GitHubやGitLabに非常に似ており、リポジトリファイルエディタ、プロジェクトの問題追跡、ユーザー管理、通知、組み込みウィキなどの豊富な機能を提供します。クロスプラットフォームであり、Linux、macOS、Windows、ARM、PowerPCアーキテクチャを含むすべての主要なオペレーティングシステムにインストールできます。

このチュートリアルでは、Ubuntu 22.04にNginxとLet’s Encrypt SSLを使用してGitea Gitサービスをインストールする方法を示します。

前提条件

  • Ubuntu 22.04を実行しているサーバー。
  • サーバーIPにポイントされた有効なドメイン名。
  • サーバーに設定されたrootパスワード。

始めに

まず、次のコマンドを実行してすべてのシステムパッケージを最新バージョンに更新およびアップグレードします:

apt update -y  
apt upgrade -y

次に、次のコマンドを実行してGitパッケージをインストールします:

apt-get install git -y

Gitパッケージがインストールされたら、次のステップに進むことができます。

MariaDBのインストールと設定

GiteaはMariaDBをデータベースバックエンドとして使用します。したがって、サーバーにインストールする必要があります。次のコマンドを実行してインストールできます:

apt install mariadb-server -y

インストール後、MariaDBを保護し、rootパスワードを設定する必要があります。次のmysql_secure_installationスクリプトを実行して保護できます:

mysql_secure_installation

このスクリプトは、rootパスワードを設定し、匿名ユーザーを削除し、リモートでのrootログインを禁止し、テストデータベースを削除します。以下のように表示されます:

Enter current password for root (enter for none):
Set root password? [Y/n]: Y
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y

MariaDBが保護されたら、次のコマンドを使用してMariaDBシェルにログインします:

mysql -u root -p

プロンプトが表示されたら、rootパスワードを入力します。次に、GLOBAL innodeb_file_per_tableをOnに変更します:

MariaDB [(none)]>SET GLOBAL innodb_file_per_table = ON;

次に、次のコマンドを使用してGitea用のデータベースとユーザーを作成します:

MariaDB [(none)]>CREATE DATABASE gitea;  
MariaDB [(none)]>CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'password';

次に、giteadbデータベースにすべての権限を付与します:

MariaDB [(none)]>GRANT ALL ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

次に、次のコマンドを使用してデータベースの文字セットを更新します:

MariaDB [(none)]>ALTER DATABASE gitea CHARACTER SET = utf8mb4 COLLATE utf8mb4_unicode_ci;

最後に、権限をフラッシュし、次のコマンドでMariaDBシェルから退出します:

MariaDB [(none)]>FLUSH PRIVILEGES;  
MariaDB [(none)]>EXIT;

次に、MariaDBのデフォルト設定ファイルを編集し、InnoDBパラメータを追加する必要があります:

nano /etc/mysql/mariadb.conf.d/50-server.cnf

[mysqld]セクション内に次の行を追加します:

innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic

ファイルを保存して閉じます。次に、MariaDBサービスを再起動して変更を適用します:

systemctl restart mariadb

この時点で、MariaDBデータベースが設定されました。次のステップに進むことができます。

Giteaのインストールと設定

まず、Giteaのダウンロードページにアクセスし、最新バージョンを選択して次のコマンドを使用して最新のGiteaバイナリをダウンロードします:

wget https://dl.gitea.io/gitea/1.17.1/gitea-1.17.1-linux-amd64

ダウンロードが完了したら、ダウンロードしたファイルを/usr/bin/ディレクトリにコピーし、実行権限を与えます:

cp gitea-1.17.1-linux-amd64 /usr/bin/gitea  
chmod 755 /usr/bin/gitea

次に、次のコマンドを使用してGitea用のシステムユーザーを作成します:

adduser --system --shell /bin/bash --group --disabled-password --home /home/git git

次に、次のコマンドを使用してGiteaのディレクトリ構造を作成します:

mkdir -p /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}  
chown git:git /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}  
chmod 750 /var/lib/gitea/{data,indexers,log}  
chmod 770 /etc/gitea

作業が完了したら、次のステップに進むことができます。

GiteaのSystemdサービスファイルを作成

次に、systemdでGiteaサービスを管理するためのsystemdサービスファイルを作成する必要があります。次のコマンドを使用して作成できます:

nano /etc/systemd/system/gitea.service

次の行を追加します:

[Unit]
Description=Gitea
After=syslog.target
After=network.target
After=mysql.service

[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target

ファイルを保存して閉じます。次に、systemdデーモンをリロードし、次のコマンドでGiteaサービスを開始します:

systemctl daemon-reload  
systemctl start gitea

次のコマンドを使用してGiteaサービスのステータスを確認できます:

systemctl status gitea

次の出力が表示されるはずです:

? gitea.service - Gitea
     Loaded: loaded (/etc/systemd/system/gitea.service; disabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-08-21 12:19:23 UTC; 8s ago
   Main PID: 24766 (gitea)
      Tasks: 6 (limit: 2242)
     Memory: 121.2M
        CPU: 800ms
     CGroup: /system.slice/gitea.service
             ??24766 /usr/bin/gitea web -c /etc/gitea/app.ini

Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:21:PreloadSettings() [I] AppPath: /usr/bin/gitea
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:22:PreloadSettings() [I] AppWorkPath: /var/lib/gitea
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:23:PreloadSettings() [I] Custom path: /var/lib/gitea/cus>
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:24:PreloadSettings() [I] Log path: /var/lib/gitea/log
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:25:PreloadSettings() [I] Configuration file: /etc/gitea/>
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:26:PreloadSettings() [I] Prepare to run install page
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:29:PreloadSettings() [I] SQLite3 is supported
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 cmd/web.go:217:listen() [I] [630222cb-6] Listen: http://0.0.0.0:3000
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 cmd/web.go:221:listen() [I] [630222cb-6] AppURL(ROOT_URL): http://localhost:3000/
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/graceful/server.go:61:NewServer() [I] [630222cb-6] Starting new Web server:>

次に、次のコマンドを使用してGiteaサービスをシステム再起動時に開始するように有効にします:

systemctl enable gitea

この時点で、Giteaは起動し、ポート3000でリッスンしています。次のステップに進むことができます。

GiteaのリバースプロキシとしてNginxを設定

デフォルトでは、Giteaはポート3000でリッスンしています。したがって、ポートを指定せずにGiteaにアクセスするためにNginxをリバースプロキシとして設定する必要があります。

まず、次のコマンドを実行してNginxウェブサーバーをインストールします:

apt-get install nginx -y

インストールが完了したら、Gitea用の新しいNginx仮想ホスト設定ファイルを作成します:

nano /etc/nginx/sites-available/gitea

次の行を追加します:

upstream gitea {
    server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name git.example.com;
    root /var/lib/gitea/public;
    access_log off;
    error_log off;

    location / {
      try_files maintain.html $uri $uri/index.html @node;
    }

    location @node {
      client_max_body_size 0;
      proxy_pass http://localhost:3000;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_max_temp_file_size 0;
      proxy_redirect off;
      proxy_read_timeout 120;
    }
}

ファイルを保存して閉じます。次に、次のコマンドを使用してNginx仮想ホスト設定ファイルを有効にします:

ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/

最後に、Nginxサービスを再起動し、次のコマンドでNginxサービスのステータスを確認します:

systemctl restart nginx
systemctl status nginx

次の出力が表示されるはずです:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-08-21 12:21:23 UTC; 5s ago
       Docs: man:nginx(8)
    Process: 24799 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 24800 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 24801 (nginx)
      Tasks: 2 (limit: 2242)
     Memory: 4.5M
        CPU: 44ms
     CGroup: /system.slice/nginx.service
             ??24801 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??24802 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Aug 21 12:21:23 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Aug 21 12:21:23 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.

この時点で、NginxはGiteaを提供するように設定されています。次のステップに進むことができます。

Let’s Encrypt SSLでGiteaを保護

まず、Certbotクライアントをインストールして、システムでLet’s Encrypt SSLをインストールおよび管理する必要があります。次のコマンドを実行してインストールできます:

apt-get install certbot python3-certbot-nginx -y

Certbotがインストールされたら、次のコマンドを実行してGiteaウェブサイト用のLet’s Encrypt SSLをダウンロードしてインストールします。

certbot --nginx -d gitea.linuxbuz.com

メールアドレスを提供し、以下のようにサービス利用規約に同意します:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
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.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing 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: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for gitea.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/gitea

次に、HTTPトラフィックをHTTPSにリダイレクトするかどうかを選択します。以下のように表示されます:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

2を入力してEnterを押すと、以下のように証明書がインストールされます:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/gitea

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://gitea.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=gitea.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/gitea.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/gitea.linuxbuz.com/privkey.pem
   Your cert will expire on 2022-11-21. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot renew"
 - 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

これで、GiteaウェブサイトはLet’s Encrypt SSLで保護されました。次のステップに進むことができます。

Giteaウェブインターフェースにアクセス

今、ウェブブラウザを開き、URL https://git.example.com/ を入力します。次のページにリダイレクトされます:

Giteaの設定

一般設定

オプション設定

Giteaデータベース名、ユーザー名、パスワード、リポジトリパス、実行ユーザー名、リッスンポート、GiteaベースURL、ログパス、Gitea管理者ユーザー名、パスワードを提供し、Giteaをインストールボタンをクリックします。インストールが完了すると、次の画面にGiteaダッシュボードが表示されます:

Giteaダッシュボード

結論

おめでとうございます!Ubuntu 22.04サーバーにNginxとLet’s Encrypt SSLを使用してGiteaを正常にインストールしました。これで、組織にGiteaを展開し、Giteaで最初のリポジトリを作成を開始できます。詳細については、Giteaのドキュメントを参照してください。

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。