git commit command programming technology code repository online cloud
Image: ribkhan/Adobe Stock

Gitea is one of the best self-hosted Git servers on the market. This Go-based package is very user-friendly, lightweight and fairly straightforward to install. Once you have it up and running, your development teams can enjoy a Git repository from within your LAN, which means sensitive code will be less likely to find its way into the hands of a third party. Gitea features notifications, a built-in editor, user management and more.

SEE: Hiring kit: Back-end Developer (TechRepublic Premium)

I want to walk you through the process of deploying the latest version of Gitea (1.17.1) on the latest version of Ubuntu Server (22.04). The process should only take you about 5-10 minutes to complete.

What you’ll need to install Gitea

The only things you’ll need for this are a running instance of Ubuntu Server (Jammy Jellyfish) and a user with sudo privileges. That’s it.

How to install the necessary dependencies

The first thing we’ll do is install the necessary dependencies. Log in to your Ubuntu Server instance and issue the command:

sudo apt-get install wget get mariadb-server -y

When the installation completes, secure the database server with the command:

sudo mysql_secure_installation

Make sure to create a new admin user password and answer y for the final questions.

How to create a database and user

The next step is to create your database. Log into the database console with:

sudo mysql -u root -p

Create the database with:

CREATE DATABASE gitea;

Next, create a database user with:

GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY "PASSWORD";

Where PASSWORD is a strong and unique password.

Flush the privileges and exit from the database console with:

FLUSH PRIVILEGES;
exit

How to install Gitea

Let’s download the latest release of Gitea and copy it to /usr/local/bin with:

sudo wget -O /usr/local/bin/gitea https://dl.gitea.io/gitea/1.17.1/gitea-1.17.1-linux-amd64

Change the permissions of the downloaded file with:

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

Next, we must create a new user with the command:

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

Create the required directories with:

sudo mkdir -pv /var/lib/gitea/{custom,data,log}

Change the ownership of the new directories:

sudo chown -Rv git:git /var/lib/gitea

Change the permissions of the main gitea directory with the command:

sudo chmod -Rv 750 /var/lib/gitea

Create a new config directory for Gitea with:

sudo mkdir -v /etc/gitea

Change the ownership of the new directory:

sudo chown -Rv root:git /etc/gitea

Change the permissions of the new directory with:

sudo chmod -Rv 770 /etc/gitea

How to create a systemd service file

Next, you must create a systemd service file for Gitea. Create the file with the command:

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

In that file, paste the following contents:

[Unit]
Description=Gitea
After=syslog.target
After=network.target

[Service]
RestartSec=3s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/

ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target

Save and close the file.

Start and enable the gitea service:

sudo systemctl enable --now gitea

How to access the Gitea web-based installer

Finally, you can finish the installation with the web-based installer. Open a browser and point it to http://SERVER:3000, where SERVER is the IP address of the hosting server.

You will see the Gitea configuration page, where you must configure the database settings (Figure A) and other options you might want to change. Make sure to change both the Server Domain and the Gitea Base URL from localhost to the IP address or domain of the hosting server.

Figure A

The Gitea configuration page.

When finished, click Install Gitea at the bottom of the page and allow the installation to complete. You will then find yourself on the Gitea login page, where you can register an account and start using your LAN-based Gitea server.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Learn more with The Mastering Linux Development Bundle from TechRepublic Academy.

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays