Gitea is a self-hosted open-source git server written in Go. It is a fork of Gogs. Gitea includes a repository file editor, project issue tracking, users managements, notifications, built-in wiki, and much more.

Gitea is a lightweight application and can be installed on low-powered systems. If you are searching for an alternative to Gitlab with a much smaller memory footprint and you don’t need all the bells and whistles that Gitlab offers, then you should definitely try Gitea.

This tutorial explains how to install and configure Gitea on Ubuntu 18.04. The same instructions apply for Ubuntu 16.04 and any other Debian-based distribution.

Prerequisites

Gitea supports SQLite, PostgreSQL, and MySQL/MariaDB as database backends.

We’ll use SQLite as the database for Gitea. If SQLite is not installed on your Ubuntu system you can install it by entering the following commands as sudo user:

sudo apt updatesudo apt install sqlite3

Installing Gitea

Gitea provides Docker images and can be installed from source, binary, and as a package.

We’ll install Gitea from binary. Complete the following steps to install Gitea on Ubuntu.

Install Git

The first step is to install Git on your server:

sudo apt updatesudo apt install git

Verify the installation by displaying the Git version:

git --version
git version 2.17.1

Create a Git user

Create a new system user which will run the Gitea application by typing:

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

The command will create a new user and group named git, and set the home directory to /home/git. The output will look something like below:

Adding system user `git' (UID 111) ...
Adding new group `git' (GID 116) ...
Adding new user `git' (UID 111) with group `git' ...
Creating home directory `/home/git' ...

Download Gitea binary

Visit the Gitea Download page and download the latest binary for your architecture. At the time of writing, the latest version is 1.10.2. If there is a new version available, change the VERSION variable in the command below.

Download the Gitea binary in the /tmp directory using the following wget command:

VERSION=1.10.2sudo wget -O /tmp/gitea https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-linux-amd64

The gitea binary can run from any location. We’ll follow the convention and move the binary to the /usr/local/bin directory:

sudo mv /tmp/gitea /usr/local/bin

Make the binary executable:

sudo chmod +x /usr/local/bin/gitea

Run the commands below to create the directories and set the required permissions and ownership:

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

The directory structure above is recommended by the official Gitea documentation.

The permissions of the /etc/gitea directory are set to 770 so that the installation wizard can create the configuration file. Once the installation is complete, we’ll set more restrictive permissions.

Create a Systemd Unit File

Gitea provides a Systemd unit file that is already configured to match our setup.

Download the file to the /etc/systemd/system/ directory by typing:

sudo wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service -P /etc/systemd/system/

Once done, enable and start the Gitea service:

sudo systemctl daemon-reloadsudo systemctl enable --now gitea

Verify that the service is started successfully:

● gitea.service - Gitea (Git with a cup of tea)
   Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-01-04 21:27:23 UTC; 3s ago
 Main PID: 14804 (gitea)
    Tasks: 9 (limit: 1152)
   CGroup: /system.slice/gitea.service
           └─14804 /usr/local/bin/gitea web --config /etc/gitea/app.ini
...

Configure Gitea

Now that Gitea is downloaded and running, it is time to finalize the installation through the web interface.

By default, Gitea listens for connections on port 3000 on all network interfaces.

If you have a UFW firewall running on your server, you’ll need to open the Gitea port:

To allow traffic on port 3000, enter the following command:

sudo ufw allow 3000/tcp

Open your browser, type http://YOUR_DOMAIN_IR_IP:3000

Database Settings:

  • Database Type: SQLite3
  • Path: Use an absolute path, /var/lib/gitea/data/gitea.db

Application General Settings:

  • Site Title: Enter your organization name.
  • Repository Root Path: Leave the default /home/git/gitea-repositories.
  • Git LFS Root Path: Leave the default /var/lib/gitea/data/lfs.
  • Run As Username: git
  • SSH Server Domain: Enter your domain or server IP address.
  • SSH Port: 22, change it if SSH is listening on other Port
  • Gitea HTTP Listen Port: 3000
  • Gitea Base URL: Use http and your domain or server IP address.
  • Log Path: Leave the default /var/lib/gitea/log

You can change the settings at any time by editing the Gitea configuration file.

Once done, hit the “Install Gitea” button. The installation is instant. When completed you will be redirected to the login page.

Click on the “Sign up now” link. The first registered user is automatically added to the Admin group.

Change the permissions of the Gitea configuration file to read-only using:

sudo chmod 750 /etc/giteasudo chmod 640 /etc/gitea/app.ini

That’s it. Gitea has been installed on your Ubuntu machine.

Upgrading Gitea

To upgrade to the latest Gitea version, simply download and replace the binary.

  1. Stop the Gitea service:sudo systemctl stop gitea
  2. Download the latest Gitea version and move it to the /home/git directory:VERSION=<THE_LATEST_GITEA_VERSION>wget -O /tmp/gitea https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-linux-amd64sudo mv /tmp/gitea /usr/local/bin
  3. Make the binary executable:sudo chmod +x /usr/local/bin/gitea
  4. Start the Gitea service:sudo systemctl restart gitea

That’s it

Hjalp dette svar dig? 233 Kunder som kunne bruge dette svar (214 Stem)