Install Forgejo, your own Git hosting

Forgejo is a single Go binary that gives you repositories, pull requests, issues and a package registry behind one web address. Install it on the plain Ubuntu 24.04 image with a systemd unit (or run it in Docker), keep the data in SQLite for a small team, put Nginx with a free certificate in front, and decide early whether Git over SSH uses port 22 or 2222. A P2 or S4 server is enough to start.

Self-hosted apps guide, updated 2026-12-03

What do you get when you self-host Forgejo?

Forgejo is a community-run Git forge: a web interface for repositories, pull requests with review, issues, wikis, releases, a container and package registry, and Forgejo Actions for CI. It is written in Go and ships as one executable, so there is no language runtime to manage. Everything it stores lives in two places: a database (SQLite, PostgreSQL or MySQL/MariaDB) and a data directory with the bare Git repositories, attachments and avatars.

There is no one-click Forgejo image in the console, and you do not need one. Create a server from Ubuntu 24.04 for the binary install, or from the Docker CE image if you prefer containers. If you want the heavier, all-in-one alternative with built-in CI and a larger feature set, the GitLab CE image is ready to pick; Forgejo needs only a fraction of its memory.

Which plan and city should a Git server use?

Forgejo idles at a few hundred MB of RAM. CPU is spent on pushes, clones of large repositories and rendering diffs; disk is the part that grows. Pick by team size and by how much CI you plan to run on the same machine:

UsePlanSpecs
Personal mirror, a few private projectsS42 vCPU, 4 GB RAM, 40 GB NVMe
Small team, SQLite, no CI on the boxP21 vCPU, 2 GB RAM, 40 GB NVMe
Team of 10~50 with PostgreSQL and a registryP42 vCPU, 4 GB RAM, 80 GB NVMe
Forge plus Actions runner on the same serverP84 vCPU, 8 GB RAM, 160 GB NVMe

Shared vCPU plans exist only in Europe; outside Europe start on P2. Choose the city closest to the people who push most often, because Git over SSH is chatty on the first handshake. All 15 cities cost the same. Included outgoing traffic on P4 is 20 TB per month in Europe, far beyond what clones of normal source trees use.

Which DNS record does Forgejo need?

One hostname, for example git.example.com. At your DNS provider create an A record pointing to the server IPv4 (here 203.0.113.10) and an AAAA record to an address from your /64, such as 2001:db8:1234:5678::1. Check it from your laptop before requesting a certificate:

dig +short git.example.com A
dig +short git.example.com AAAA

The same name serves the web interface and SSH clone URLs, so users will see git@git.example.com:team/app.git. The guide on pointing a domain covers TTLs and propagation if the answer does not show up yet.

How do you install the Forgejo binary with systemd?

Install Git and create a system user that will own the repositories:

apt update && apt install -y git git-lfs
adduser --system --shell /bin/bash --gecos "Git Version Control" --group --disabled-password --home /home/git git
mkdir -p /var/lib/forgejo /etc/forgejo
chown git:git /var/lib/forgejo && chmod 750 /var/lib/forgejo
chown root:git /etc/forgejo && chmod 770 /etc/forgejo

Download the current release from the Forgejo releases page on Codeberg. Set VER to the version listed there and ARCH to amd64 on Performance, Shared and Dedicated plans or arm64 on Arm plans:

VER=11.0.0      # replace with the current release
ARCH=amd64
wget -O /usr/local/bin/forgejo https://codeberg.org/forgejo/forgejo/releases/download/v$VER/forgejo-$VER-linux-$ARCH
chmod 755 /usr/local/bin/forgejo
forgejo --version

Create /etc/systemd/system/forgejo.service:

[Unit]
Description=Forgejo
After=network.target postgresql.service

[Service]
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/forgejo/
ExecStart=/usr/local/bin/forgejo web --config /etc/forgejo/app.ini
Restart=always
Environment=USER=git HOME=/home/git FORGEJO_WORK_DIR=/var/lib/forgejo

[Install]
WantedBy=multi-user.target

Start it with systemctl daemon-reload && systemctl enable --now forgejo. Forgejo now listens on port 3000. Do not open that port to the world; the installer page is reached through an SSH tunnel (ssh -L 3000:127.0.0.1:3000 root@203.0.113.10, then http://localhost:3000) or after the proxy below is in place.

Once the installer has written app.ini, tighten permissions: chmod 750 /etc/forgejo && chmod 640 /etc/forgejo/app.ini.

Should you run Forgejo in Docker instead?

On the Docker CE image a Compose file is just as quick. The rootful image runs its own OpenSSH inside the container, which you map to host port 2222:

services:
  forgejo:
    image: codeberg.org/forgejo/forgejo:11
    restart: always
    environment:
      - USER_UID=1000
      - USER_GID=1000
    volumes:
      - ./forgejo:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "127.0.0.1:3000:3000"
      - "2222:22"

Replace the tag with the current major version. Everything lives under ./forgejo, including gitea/conf/app.ini inside the volume. Docker publishes ports past ufw rules, so bind the web port to 127.0.0.1 as shown and let the host proxy handle HTTPS. Both methods are fine; the binary install is simpler to debug and the container is simpler to move.

SQLite or PostgreSQL: which database should you pick?

SQLite is a file in the data directory. It needs no extra service, backs up with the rest of the data and handles a small team easily. Its weak point is many writes at the same moment, for example dozens of CI jobs updating statuses while people browse.

PostgreSQL is the better choice once more than a handful of people use the forge every day, or when you plan to run Actions heavily. On Ubuntu 24.04:

apt install -y postgresql
sudo -u postgres psql -c "CREATE ROLE forgejo WITH LOGIN PASSWORD 'change-this-password';"
sudo -u postgres psql -c "CREATE DATABASE forgejodb WITH OWNER forgejo TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';"

In the installer pick PostgreSQL, host 127.0.0.1:5432, user forgejo, database forgejodb. The result in app.ini is a [database] section with DB_TYPE = postgres. On Rocky or Alma Linux the package is postgresql-server via dnf, followed by postgresql-setup --initdb. Moving from SQLite to PostgreSQL later is possible with a dump and restore, but choosing up front saves an evening.

How do you handle Git over SSH on port 22 or 2222?

Users want short clone URLs, and port 22 gives them that. You have three workable layouts:

  • Share the system OpenSSH on port 22. Forgejo writes keys into /home/git/.ssh/authorized_keys with a forced command, so git@git.example.com lands in Forgejo while your admin logins keep working on the same port. Keep START_SSH_SERVER = false and set SSH_DOMAIN = git.example.com in the [server] section. This is the default for the binary install.
  • Built-in SSH server on 2222. Set START_SSH_SERVER = true and SSH_LISTEN_PORT = 2222, then clone URLs look like ssh://git@git.example.com:2222/team/app.git.
  • Move admin SSH, give 22 to Git. Change Port 22 to another port in /etc/ssh/sshd_config (on Ubuntu 24.04 also run systemctl edit ssh.socket because SSH is socket-activated), then let Forgejo or the container own 22.

For the Docker layout the simplest path is 2222. Whatever you choose, make sure SSH_PORT in app.ini matches what users must type, because Forgejo prints it in every clone box. Test with ssh -T -p 2222 git@git.example.com; a greeting with your user name means the key is recognised.

How do you put HTTPS in front with Nginx?

Install Nginx and Certbot, then create /etc/nginx/sites-available/forgejo:

server {
    listen 80;
    listen [::]:80;
    server_name git.example.com;
    client_max_body_size 512M;
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
apt install -y nginx certbot python3-certbot-nginx
ln -s /etc/nginx/sites-available/forgejo /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
certbot --nginx -d git.example.com

Raise client_max_body_size if you push large LFS objects or container images. In app.ini set ROOT_URL = https://git.example.com/ and HTTP_ADDR = 127.0.0.1, then restart Forgejo. More on certificates is in Nginx with HTTPS.

Which firewall ports should be open?

Open only what users reach: 22 (or your moved admin port), 80 for certificate renewal and redirects, 443 for the web interface, and 2222 if Git SSH runs there.

ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 2222/tcp   # only for the built-in or Docker SSH layout
ufw enable

Port 3000 stays closed because Forgejo listens on localhost. The firewall guide covers ufw and firewalld in detail.

How do runners fit in, and how do you update and back up?

Runners. Forgejo Actions uses workflow files similar in shape to other YAML CI systems, executed by a separate program, Forgejo Runner. Enable Actions in app.ini with [actions] and ENABLED = true, create a registration token under Site administration, Actions, Runners, and register the runner with forgejo-runner register. Run the runner on a second server where possible: builds are bursty and untrusted code should not share a disk with your repositories. The CI runners page helps size it.

Updates. Read the release notes, back up, replace the binary with the new version and run systemctl restart forgejo. Forgejo migrates the database on start. With Docker, change the tag and run docker compose pull && docker compose up -d.

Backups. forgejo dump writes one zip with the database, repositories, configuration and attachments:

cd /var/lib/forgejo
sudo -u git forgejo dump --config /etc/forgejo/app.ini --file /var/lib/forgejo/dump-$(date +%F).zip

Copy the zip off the server with restic or rsync and delete old ones. The optional backup add-on ($2.41 per month on P4) keeps 7 daily copies of the whole disk as a second layer; restoring one means a support ticket naming the server and day. See backups and restore.

Troubleshooting. journalctl -u forgejo -e shows start errors; a wrong ROOT_URL causes broken redirects after login; Permission denied (publickey) on clone usually means the key was added to the admin account instead of the Forgejo user profile, or SSH_PORT does not match.

Questions about this guide

Can Forgejo run on an Arm server?

Yes. Download the linux-arm64 binary or use the multi-arch container image. Arm plans such as A4 are available in Frankfurt, Nuremberg, Helsinki and Amsterdam.

How much disk does a Git server need?

Source trees are small; LFS objects, release files and container images are not. Check usage with du -sh /var/lib/forgejo/* and move to a larger plan by migrating when space runs low, as described in moving to a bigger plan.

Can I mirror repositories from another forge?

Yes. Use New migration in the web interface, paste the source URL and tick mirror. Forgejo then pulls on a schedule you set.

Does Forgejo send email?

Only if you configure the [mailer] section with an SMTP relay. Outgoing port 25 is closed by default, so use an authenticated relay on port 587, or ask support about port 25.

Is forgejo dump enough as a backup?

It covers everything Forgejo needs to restore, but a copy that stays on the same disk is not a backup. Ship it to another server or storage and test a restore once.

Can I stop public sign-ups?

Set DISABLE_REGISTRATION = true in the [service] section and create accounts yourself, or keep registration on with REQUIRE_SIGNIN_VIEW = true for a private forge.