How To Install Gitea Git service on Ubuntu 20.04|18.04|16.04

Posted on 17 views

Welcome to our guide on how to Install Gitea self-hosted Git service on Ubuntu 20.04|18.04|16.04. Gitea is a painless self-hosted Git service forked from Gogs and similar to GitHub, Bitbucket, and Gitlab.

Gitea main goal is to provide the fastest, easiest, and most painless way of setting up a self-hosted Git service. Being written in Go, it is distributed as a binary package that runs across all platforms and architectures that Go supports.

For CentOS 7 / CentOS 8 users, check: How to Install Gitea self-hosted Git service on CentOS 7/8

It runs on  Linux, macOS, and Windows, on architectures like amd64, i386, ARM, PowerPC, and others. Install Gitea on Ubuntu 20.04/18.04/16.04 server by following the steps provided below.

Gitea System setup

The setup is comprised of

  • Ubuntu Server
  • MariaDB database server
  • Git version control
  • Gitea service with systemd

Step 1: Create a git system user

Run the following commands to add a user git to manage Gitea on your system.

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

The command id should display user id and group id

$ id git
uid=112(git) gid=117(git) groups=117(git)

Step 2: Install MariaDB database server

We will use MariaDB to store Gitea data, install MariaDB on your server.

sudo apt -y install mariadb-server

Create a database for Gitea.

$ sudo mysql -u root -p

CREATE DATABASE gitea;
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY "StrongPassword";
FLUSH PRIVILEGES;
QUIT;

Step 3: Install Gitea on Ubuntu 20.04/18.04

Now download gitea binary from the Downloads page. Check the latest release before downloading it.

curl -s  https://api.github.com/repos/go-gitea/gitea/releases/latest |grep browser_download_url  |  cut -d '"' -f 4  | grep '\linux-amd64$' | wget -i -

Move the downloaded binary file to the /use/local/bindirectory

chmod +x gitea-*-linux-amd64
sudo mv gitea-*-linux-amd64 /usr/local/bin/gitea

You can confirm version installed using.

$ gitea --version
Gitea version 1.14.4 built with GNU Make 4.1, go1.16.5 : bindata, sqlite, sqlite_unlock_notify

Create the required directory structure.

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

The web installer will need write permission configuration file under /etc/gitea

Create a systemd service unit

sudo vim /etc/systemd/system/gitea.service

Configure the file to set UserGroup and WorkDir.

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
After=mysql.service

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# If you want to bind Gitea to a port below 1024 uncomment
# the two values below
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

Reload systemd and restart service

sudo systemctl daemon-reload
sudo systemctl restart gitea

Also enable the service to start on boot

sudo systemctl enable gitea

Sample status output.

$ systemctl status gitea
* gitea.service - Gitea (Git with a cup of tea)
   Loaded: loaded (/etc/systemd/system/gitea.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-10-01 12:25:19 PDT; 3s ago
 Main PID: 6919 (gitea)
    Tasks: 10 (limit: 1111)
   CGroup: /system.slice/gitea.service
           `-6919 /usr/local/bin/gitea web -c /etc/gitea/app.ini
.......

Step 4: Configure Nginx Proxy

Install nginx on Debian 10.

sudo apt -y install nginx

If ufw is enabled, allow http and https ports.

for i in http https; do
 sudo ufw allow $i
done

Create Nginx configuration file for Gitea

sudo vim /etc/nginx/conf.d/gitea.conf

Paste below data into the file created.

server 
    listen 80;
    server_name git.example.com;

    location / 
        proxy_pass http://localhost:3000;
    

Set correct domain name and restart nginx service.

sudo systemctl restart nginx

Step 5: Configure Gitea on Ubuntu 20.04/18.04

Start the installation by visiting http://servehostname/install

Set database authentication

On the first page, set the database connection:

gitea-configure-mysql-ubuntu-18.04-min-1024x449

The username and password provided should match the ones provided in the Database configuration section. If the database server is on a different host, provide the IP address under the Host section.

Set Application General Settings

Set SSH Server domain – should be same domain used in Nginx configuration.

gitea-domain-name-setting-min-1-1024x563

Provide application URL, and HTTP Listen port. Since we’re using Nginx proxy, there is no need to change default values.

Disable User self-registration

You can disable User self-registration under “Server and Other Services Settings”. This means the admin user will manually create user accounts.

install-gogs-git-service-ubuntu-18.04-disable-self-registration-min-1024x465

Optionally create an admin user account. By default, the root user will gain admin access automatically.

install-gogs-git-service-ubuntu-18.04-configure-admin-account-min-1024x388

When done with the configurations, click the “Install Gitea” button to finish the installation. On a successful installation, you should be logged into Gitea administration console.

install-gitea-debian-10-06-1024x343

You have successfully install Gitea on Ubuntu 20.04/18.04/16.04 server. Have a happy Git time, refer to Gitea Documentation for advanced configurations and usage guides.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.