Installation from binary


目录

Install Forgejo and Git, create git user

[!note] Note This guide uses git.example.com and x.y.z for illustrative purpose. Replace with your domain and the used Forgejo version as appropriate.

First, download the Forgejo binary for your CPU architecture and verify the GPG signature, as described on the Forgejo download page.

Next, copy the downloaded Forgejo binary to /usr/local/bin/ (renaming it to "forgejo") and make it executable:

sudo cp forgejo-x.y.z-linux-amd64 /usr/local/bin/forgejo
sudo chmod 755 /usr/local/bin/forgejo

Make sure git and git-lfs are installed on your system. On Debian GNU/Linux you can use:

sudo apt install git git-lfs

Create a user git on the system. Forgejo will run as that user, and when accessing git through SSH (which is the default), this user is part of the URL (for example in git clone git@git.example.com:YourOrg/YourRepo.git the git before the @ is the user you'll create now). On Debian, Ubuntu and their derivatives that's done with:

sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' \
  --group --disabled-password --home /home/git git

On Linux distributions not based on Debian/Ubuntu (this should at least work with Red Hat derivatives like Fedora, CentOS etc.), run this instead:

sudo groupadd --system git
sudo useradd --system --shell /bin/bash --comment 'Git Version Control' \
   --gid git --home-dir /home/git --create-home git

Create directories Forgejo will use

Now create the directories Forgejo will use and set access permissions appropriately:

sudo mkdir /var/lib/forgejo
sudo chown git:git /var/lib/forgejo && sudo chmod 750 /var/lib/forgejo

This is the directory Forgejo will store its data in, including your Git repositories.

sudo mkdir /etc/forgejo
sudo chown root:git /etc/forgejo && sudo chmod 770 /etc/forgejo

This is the directory Forgejo's config, called app.ini, is stored in. Initially it needs to be writable by Forgejo, but after the installation you can make it read-only for Forgejo because then it shouldn't modify it anymore.

Optional: Set up database

When using sqlite as Forgejo's database, nothing needs to be done here.

If you need a more powerful database, you can use MySQL/MariaDB or PostgreSQL (apparently sqlite is good enough for at least 10 users, but might even suffice for more).

See Forgejo's Database Preparation guide for setup instructions.

Install systemd service for Forgejo

Forgejo provides a systemd service script. Download it to the correct location:

sudo wget -O /etc/systemd/system/forgejo.service https://codeberg.org/forgejo/forgejo/raw/branch/forgejo/contrib/systemd/forgejo.service

If you're not using sqlite, but MySQL or MariaDB or PostgreSQL, you'll have to edit that file (/etc/systemd/system/forgejo.service) and uncomment the corresponding Wants= and After= lines. Otherwise it should work as it is.

After adding or modifying a systemd service file, you will need to reload systemd.

sudo systemctl daemon-reload

Now enable and start the Forgejo service, so you can go on with the installation:

sudo systemctl enable forgejo.service
sudo systemctl start forgejo.service

Forgejo's web-based configuration

Access the Forgejo web UI by opening http://localhost:3000/ in your local web browser. Replace localhost with the server's local IP address if necessary.

If it doesn't work:

You should be greeted by Forgejo's "Initial Configuration" screen. The settings should be mostly self-explanatory, some hints:

Once you're done configuring, click Install Forgejo and a few seconds later you should be on the dashboard (if you created an administrator account) or at the login/register screen, where you can create an account to then get to the dashboard.

So far, so good, but we're not quite done yet - some manual configuration in the app.ini is needed.

Further configuration in Forgejo's app.ini

Stop the forgejo service:

sudo systemctl stop forgejo.service

While at it, make /etc/forgejo/ and the app.ini read-only for the git user (Forgejo doesn't write to it after the initial configuration):

sudo chmod 750 /etc/forgejo && sudo chmod 640 /etc/forgejo/app.ini

Now, (as root), edit /etc/forgejo/app.ini.

[!note] Note You'll probably find the Configuration Cheat Sheet and the Example app.ini that contains all options incl. descriptions helpful.

The following changes are recommended if dealing with many large files:

When you're done editing the app.ini, save it and start the Forgejo service again:

sudo systemctl start forgejo.service

You can test sending a mail by clicking the user button on the upper right of the Forgejo page ("Profile and Settings"), then Site Administration, then Configuration and under Mailer Configuration type in your mail address and click Send Testing Email.

General hints for using Forgejo

Sometimes you may want/need to use the Forgejo command line interface. Keep in mind that:

So all in all your command might look like:

$ sudo -u git forgejo -w /var/lib/forgejo -c /etc/forgejo/app.ini admin user list

For convenience, you could create a /usr/local/bin/forgejo.sh with the following contents:

#!/bin/sh
sudo -u git forgejo -w /var/lib/forgejo -c /etc/forgejo/app.ini "$@"

and make it executable:

sudo chmod 755  /usr/local/bin/forgejo.sh

Now if you want to call forgejo on the commandline (for the default system-wide installation in /var/lib/forgejo), instead of the long line shown above, use:

$ forgejo.sh admin user list

You can always call forgejo and its subcommands with -h or --help to make it output usage information like available options and (sub)commands, for example to show available subcommands to administrate users on the commandline:

$ forgejo admin user -h

版本号 #4
由 cocobook-sync 创建于 2026-10-28 16:40:55 UTC
由 cocobook-sync 更新于 2026-10-29 03:45:43 UTC