Gitea is a self-hosted open-source git server written in Go. It comes with 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 less powerful systems. If you are searching for a Gitlab alternative with a much smaller memory footprint and don’t need all the bells and whistles Gitlab offers, you should try Gitea.

This article shows you how to install and configure Gitea on CentOS 8.

Prerequisites

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

We’ll use SQLite. It is a lightweight database that stores data within a single file. If SQLite is not installed on your CentOS machine you can install it by running the following command as sudo user :

sudo dnf install sqlite

We’re assuming that SELinux is either disabled or set to permissive mode.

Installing Gitea

Gitea can be installed from source, binary, and as a package. It can be also deployed as a Docker image. We’ll install Gitea using thr binary.

Install Git

The first step is to install Git on your CentOS:

sudo dnf install git

Verify the installation by displaying the Git version:

git --version
git version 2.18.4

Create a Git user

Create a new system user to run the Gitea application:

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

The command will create a new user and group named git, and set the home directory to /home/git.

Download Gitea binary

The latest Gitea binary can be downloaded from the Gitea Download page . Make sure you download the right binary for your architecture.

At the time of writing, the latest version is 1.12.3. If there is a new version available, change the VERSION variable in the command below.

Use wget to download the Gitea binary in the /tmp directory:

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

You can run the binary 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

The following commands will create the necessary 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 files. Once the installation is complete, we’ll set more restrictive permissions.

Create a Systemd Unit File

Gitea provides a Systemd unit file that is 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:

sudo systemctl status gitea
● 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 up 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. You’ll need to configure your firewall to enable access to the Gitea web interface:

sudo firewall-cmd --permanent --zone=public --add-port=3000/tcpsudo firewall-cmd --reload

Open your browser, enter http://YOUR_DOMAIN_IR_IP:3000/install, and the initial configurations page will appear:

<img alt="" data-action="zoom" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/08/echo/gitea-install.jpg" data-ez ezimgfmt="ng ngcb26 src srcset" loading="lazy" src="data:image/svg xml,”>

Fill the required fields as follow:

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

Later, you can change the settings 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.

To make the installation more secure, 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 CentOS machine.

Configuring Nginx as SSL Termination Proxy

This step is optional, but it is highly recommended. To use Nginx as a reverse proxy , you need to have a domain or subdomain pointing to your server public IP. In this tutorial, we will use git.example.com.

First, install Nginx and generate a free Let’s Encrypt SSL certificate using the guides below:

Once done, open your text editor and edit the domain server block file:

sudo nano /etc/nginx/conf.d/git.example.com.conf

/etc/nginx/conf.d/git.example.com.conf

server {
    listen 80;
    server_name git.example.com;

    include snippets/letsencrypt.conf;
    return 301 https://git.example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name git.example.com;

    proxy_read_timeout 720s;
    proxy_connect_timeout 720s;
    proxy_send_timeout 720s;

    client_max_body_size 50m;

    # Proxy headers
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;

    # SSL parameters
    ssl_certificate /etc/letsencrypt/live/git.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/git.example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/git.example.com/chain.pem;
    include snippets/letsencrypt.conf;
    include snippets/ssl.conf;

    # log files
    access_log /var/log/nginx/git.example.com.access.log;
    error_log /var/log/nginx/git.example.com.error.log;

    # Handle / requests
    location / {
       proxy_redirect off;
       proxy_pass http://127.0.0.1:3000;
    }
}

Don’t forget to replace git.example.com with your Gitea domain and set the correct path to the SSL certificate files. The HTTP traffic is redirected to HTTPS .

Once done, restart the Nginx service for changes to take effect:

sudo systemctl restart nginx

Next, change the Gitea domain and root url. To do so, open the configuration file and edit the following lines:

sudo nano /etc/gitea/app.ini

/etc/gitea/app.ini

[server]
DOMAIN           = git.example.com
ROOT_URL         = https://git.example.com/

Restart the Gitea service by typing:

sudo systemctl restart gitea

At this point, Gitea proxy is configured, and you can access it at: https://git.example.com

Configuring Email Notifications

For the notification emails to be sent out, you can either install Postfix or use a transactional mail service such as SendGrid, MailChimp, MailGun, or SES.

To enable email notifications, open the configuration file and edit the following lines:

sudo nano /etc/gitea/app.ini

/etc/gitea/app.ini

[mailer]
ENABLED = true
HOST    = SMTP_SERVER:SMTP_PORT
FROM    = SENDER_EMAIL
USER    = SMTP_USER
PASSWD  = YOUR_SMTP_PASSWORD

Make sure you use the correct SMTP server information.

Each time you edit the app.ini file, you need to restart the Gitea service for changes to take effect:

sudo systemctl restart gitea

To verify the settings and send a test email, log in to Gitea and go to: Site Administration > Configuration > SMTP Mailer Configuration.

Gitea also allows you to connect to Slack by creating a web webhook and send notifications to your Slack channels .

Upgrading Gitea

Upgrading to the latest Gitea version is a straightforward task. You only need to download and replace the binary.

  1. Stop the Gitea service:

    sudo systemctl stop gitea
  2. Download the latest Gitea binary and move it to the /usr/local/bin directory:

    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. Restart the Gitea service:

    sudo systemctl restart gitea

That’s it.

Conclusion

We have shown you how to install Gitea on CentOS 8. You should now visit the Gitea documentation page and learn how to configure your installation and create your first project.

If you have questions, feel free to leave a comment below.