Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Forgejo Install from Binary

From Thibble Wiki

Installation:

Download Forgejo binary for your CPU architecture and verify the GPG signature. Copy the binary to /usr/local/bin/ and make it executable.

  1. cp forgejo-1.21.5-0-linux-amd64 /usr/local/bin/forgejo
  2. chmod 755 /usr/local/bin/forgejo

Ensure git and git-lfs are installed:

  1. apt install git git-lfs

Create a user git on the system:

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

Create necessary directories for Forgejo:

  1. mkdir /var/lib/forgejo
  2. chown git:git /var/lib/forgejo && chmod 750 /var/lib/forgejo
  1. mkdir /etc/forgejo
  2. chown root:git /etc/forgejo && chmod 770 /etc/forgejo

Optional: Set up database: (If not using SQLite)

Follow Forgejo's Database Preparation guide for setup. Install systemd service for Forgejo:

Download the systemd service script:

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

Enable and start the Forgejo service:

  1. systemctl enable forgejo.service
  2. systemctl start forgejo.service

Forgejo's web-based configuration:

Access Forgejo in your browser at http://git.example.com:3000/. If encountering issues, check service status and logs:

  1. systemctl status forgejo.service
  2. journalctl -n 100 --unit forgejo.service

Follow on-screen instructions to complete initial configuration. Further configuration in Forgejo's app.ini:

Stop Forgejo service:

  1. systemctl stop forgejo.service

Make /etc/forgejo/ and app.ini read-only for the git user:

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

Edit /etc/forgejo/app.ini to adjust configurations.

Start Forgejo service again:

  1. systemctl start forgejo.service

General hints for using Forgejo:

Run Forgejo CLI as the git user. Specify Forgejo work path and config path. Optionally, create a script for easier CLI usage:

  1. !/bin/sh

sudo -u git forgejo -w /var/lib/forgejo -c /etc/forgejo/app.ini "$@" Make it executable:

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

Now, Forgejo commands can be executed simply by calling forgejo.sh [command].

To turn the script into a service for systemctl, follow these steps:

Open the forgejo.service file for editing: sudo nano /etc/systemd/system/forgejo.service Update the file to include the User directive: [Unit] Description=Forgejo Command Line Interface After=network.target

[Service] Type=simple User=git ExecStart=/usr/local/bin/forgejo.sh Restart=on-failure

[Install] WantedBy=multi-user.target Save and close the file.

Reload systemd to read the new service file:

sudo systemctl daemon-reload Enable and start the forgejo service: sudo systemctl enable forgejo.service sudo systemctl start forgejo.service Now, the forgejo.sh script will be executed with the git user permissions when managed by systemctl.