How to Install Gitea Git Service on Ubuntu 18.04

Gitea is a free and opsource version of Git written in Go. It’s forked from Gogs and very similar to GitHub, Bitbucket, and Gitlab. With Gitea, you can easily set up a self-hosted Git service without any problem. It is simple, easy to use, lightweight and requires minimal hardware to run it. Gitea comes with a rich set of features including time tracking, repository branching, issues tracking, file locking, merging and much more. Gitea can be installed on all popular operating systems like Windows, macOS, Linux and ARM.

In this tutorial, we will explain how to install and configure Gitea Git service on Ubuntu 18.04 server.

Requirements

  • A server running Ubuntu 18.04.
  • A static IP address set up on your server.

Getting Started

Let’s start by updating your system’s package repository with the latest version.

You can do it with the following command:

# apt-get update -y
# apt-get upgrade -y

Once the repository is updated, restart your server to apply all the changes.

Install Required Packages

Next, you will need to install MariaDB database server, Git and other required packages to your server. You can install all of them with the following command:

# apt-get install mariadb-server git -y

Once installed, start MariaDB service and enable it to start on boot time with the following command:

# systemctl start mariadb
# systemctl status mariadb

Once you are finished, you can proceed to the next step.

Configure MariaDB

Next, you will need to create database and user for Gitea.

To do so, log in to MariaDB shell with the following command:
# mysql -u root -p

Enter your root password when prompt, then change the GLOBAL innodeb_file_per_table to On:

 MariaDB [(none)]> SET GLOBAL innodb_file_per_table = ON;

Next, create a database and user for Gitea with the following command:

# MariaDB [(none)]> CREATE DATABASE giteadb;
# MariaDB [(none)]> CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'gitea';

Next, grant all the privileges to Gitea and alter database with the following command:

# MariaDB [(none)]> GRANT ALL ON giteadb.* TO 'gitea'@'localhost' IDENTIFIED BY 'gitea' WITH GRANT OPTION;
# MariaDB [(none)]> ALTER DATABASE giteadb CHARACTER SET = utf8mb4 COLLATE utf8mb4_unicode_ci;

Finally, flush the privileges and exit from the MariaDB shell with the following command:

# MariaDB [(none)]> FLUSH PRIVILEGES;
# MariaDB [(none)]> EXIT;

Next, open the MariaDB default config file and tweak some settings:

 nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add the following lines:

innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic

Save and close the file, then restart MariaDB service to apply configuration changes:

systemctl restart mariadb

Install Gitea

First, go to the Git hub repository and download the latest version of Gitea with the following command:

# wget https://github.com/go-gitea/gitea/releases/download/v1.9.0/gitea-1.9.0-linux-amd64

Once downloaded, copy the downloaded binary file to the /usr/local/bin directory:

 cp gitea-1.9.0-linux-amd64 /usr/local/bin/gitea 

Once you have finished, you can proceed to the next step.

Next, you will need to create a system user for Gitea. You can do it with the following command:

# adduser --system --shell /bin/bash --group  --disabled-password --home /home/gitea gitea

Next, create a directory structure for Gitea with the following command:

# mkdir -p /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}
# chown gitea:gitea /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}
# chmod 750 /var/lib/gitea/{data,indexers,log}
# chmod 770 /etc/gitea>

Create Systemd Service file for Gitea

Next, you will need to create a systemd service file to manage the Gitea service. You can do it with the following command:

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

Add the following lines:

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

[Service]
RestartSec=2s
Type=simple
User=root
Group=root
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=root HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target

Save and close the file. Then, reload the systemd daemon with the following command:

# systemctl daemon-reload

Next, start Gitea service and enable it to start on boot with the following command:

# systemctl start gitea
# systemctl enable gitea

You can now check the status of Gitea service with the following command:

# systemctl status gitea

If everything goes fine, you should see the following output:

  • gitea.service - Gitea
Loaded: loaded (/etc/systemd/system/gitea.service; disabled; vendor preset: enabled) Active: active (running) since Wed 2019-08-07 05:05:24 UTC; 46s ago Main PID: 3859 (gitea) Tasks: 9 (limit: 1098) CGroup: /system.slice/gitea.service └─3859 /usr/local/bin/gitea web -c /etc/gitea/app.ini Aug 07 05:05:24 hitesh gitea[3859]: 2019/08/07 05:05:24 routers/init.go:74:GlobalInit() [T] Custom path: /var/lib/gitea/custom Aug 07 05:05:24 hitesh gitea[3859]: 2019/08/07 05:05:24 routers/init.go:75:GlobalInit() [T] Log path: /var/lib/gitea/log Aug 07 05:05:24 hitesh gitea[3859]: 2019/08/07 05:05:24 ...dules/setting/log.go:226:newLogService() [I] Gitea v1.9.0 built with GNU Make 4.1, g Aug 07 05:05:24 hitesh gitea[3859]: 2019/08/07 05:05:24 ...dules/setting/log.go:269:newLogService() [I] Gitea Log Mode: Console(Console:info) Aug 07 05:05:24 hitesh gitea[3859]: 2019/08/07 05:05:24 ...les/setting/cache.go:42:newCacheService() [I] Cache Service Enabled Aug 07 05:05:24 hitesh gitea[3859]: 2019/08/07 05:05:24 ...s/setting/session.go:45:newSessionService() [I] Session Service Enabled Aug 07 05:05:24 hitesh gitea[3859]: 2019/08/07 05:05:24 routers/init.go:106:GlobalInit() [I] SQLite3 Supported Aug 07 05:05:24 hitesh gitea[3859]: 2019/08/07 05:05:24 routers/init.go:37:checkRunMode() [I] Run Mode: Development Aug 07 05:05:25 hitesh gitea[3859]: 2019/08/07 05:05:25 cmd/web.go:151:runWeb() [I] Listen: http://0.0.0.0:3000 Aug 07 05:05:25 hitesh gitea[3859]: 2019/08/07 05:05:25 ...ce/gracehttp/http.go:142:Serve() [I] Serving [::]:3000 with pid 3859

Access Gitea

Gitea is now installed and configured, it’s time to access Gitea web interface.
Open your web browser and type the URL http://your-server-ip:3000/install. You will be redirected to the Gitea installation wizard as shown below:


Now, provide all the required information like, database name, database username, Gitea URL, Gitea admin username and password. Then, click on the Install Gitea button. Once the installation has been completed, you will be redirected to the Gitea dashboard as shown below:

Congratulations! you have successfully installed and configured Gitea git service on Ubuntu 18.04 server 🙂

You can now deploy your own Gitea server in the production environment and manage repository from the central location.

To write a comment on this article, fill out the form below. Fields marked with an asterisk (*) are required.