How to Install Gitea on Clear Linux

Gitea is a self-hosted Git service written in Go. It provides a web interface to manage Git repositories, users, and permissions. In this tutorial, we will learn how to install Gitea on Clear Linux Latest.

Prerequisites

Before we proceed with the installation, make sure you have the following:

Step 1 - Update the System

First, we need to update the system packages to the latest version:

sudo swupd update

Step 2 - Install Required Packages

Next, we need to install the required packages for Gitea to work properly. The list of packages includes:

For SQLite, we can install it using the following command:

sudo swupd bundle-add sqlite

For other databases, you can install them using Clear Linux's software manager or package manager.

For Nginx or Apache, we need to install the respective packages using the following commands:

Nginx:

sudo swupd bundle-add nginx

Apache:

sudo swupd bundle-add apache-httpd

Step 3 - Download and Install Gitea

We can download the latest version of Gitea from its official website https://gitea.io. Navigate to the download page and copy the link for the latest binary.

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

Next, we need to make the binary executable:

chmod +x gitea-latest-linux-amd64

Finally, we can move the binary to /usr/local/bin using the following command:

sudo mv gitea-latest-linux-amd64 /usr/local/bin/gitea

Step 4 - Configure Gitea

We need to create a new system user for running the Gitea service. To create a new user named git run the following command:

sudo useradd -r -s /bin/bash git

Next, we need to create a Gitea configuration file. We can create the configuration file in /etc/gitea directory using the following command:

sudo mkdir /etc/gitea
sudo nano /etc/gitea/app.ini

Copy the following content to the configuration file:

[server]
PROTOCOL = http
DOMAIN   = <your domain>
HTTP_PORT = 3000
ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/
SSH_DOMAIN = <your domain>
SSH_PORT = 22
OFFLINE_MODE = false
LFS_START_SERVER = false
etc...

[database]
DB_TYPE  = sqlite3
HOST     = localhost:3306
NAME     = gitea
USER     = gitea
PASSWD   = thepassword
SSL_MODE = disable
etc...

[repository]
ROOT = /data/git/repositories

[repository.upload]
TEMP_PATH = /tmp/gitea/uploads

[session]
PROVIDER = file
PROVIDER_CONFIG = /var/lib/gitea/sessions

[security]
SECRET_KEY = insecuresupersecretkey

[service]
REGISTER_EMAIL_CONFIRM = false
etc...

Make sure to modify the configuration file according to your setup.

##Step 5 - Configure Nginx (Optional)

If you have installed Nginx earlier, we can configure it to serve as a reverse proxy for Gitea.

Create a new Nginx configuration file /etc/nginx/sites-available/gitea using your preferred text editor. Copy the following content to the file:

proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=gitea-cache:10m max_size=30m;
server {
    listen 80;
    server_name git.example.com;

    access_log /var/log/nginx/gitea.log;

    location / {
        proxy_pass http://localhost:3000/;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        # Enables websockets proxying
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # Provides buffer time for backend to finish request
        proxy_read_timeout 5m;
        proxy_buffering off;
        chunked_transfer_encoding off;
    }

    # serve static files from data directory
    location /static/ {
        root /var/lib/gitea;
    }
}

Make sure to replace git.example.com with the correct domain name.

Next, create a symbolic link to enable the site configuration:

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

Finally, restart Nginx to apply the changes:

sudo systemctl reload nginx

Step 6 - Start Gitea Service

Now that we have configured Gitea and Nginx (optional), we can start the Gitea service using the following command:

sudo systemctl enable --now gitea

The service will start at boot and run as the git user.

Step 7 - Access Gitea Web Interface

Once the service is up and running, we can access the Gitea web interface using the browser. Open your browser and navigate to http://<your domain>:3000. You should see the Gitea login page.

Congratulations! You have successfully installed Gitea on Clear Linux Latest.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!