We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Install Gitea Git service on Ubuntu 22.04|20.04|18.04|16.04

Learn how to – Install Gitea Git service on Ubuntu 22.04|20.04|18.04|16.04.

Welcome to our guide on how to Install Gitea self-hosted Git service on Ubuntu 22.04|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 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 update
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

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.19.2 built with GNU Make 4.1, go1.20.3 : 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; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-05-02 15:47:52 UTC; 6s ago
   Main PID: 2210 (gitea)
      Tasks: 7 (limit: 4537)
     Memory: 109.5M
        CPU: 735ms
     CGroup: /system.slice/gitea.service
             └─2210 /usr/local/bin/gitea web -c /etc/gitea/app.ini

May 02 15:47:52 jammy gitea[2210]: 2023/05/02 15:47:52 ...s/install/setting.go:21:PreloadSettings() [I] AppPath: /usr/local/bin/gitea
May 02 15:47:52 jammy gitea[2210]: 2023/05/02 15:47:52 ...s/install/setting.go:22:PreloadSettings() [I] AppWorkPath: /var/lib/gitea
May 02 15:47:52 jammy gitea[2210]: 2023/05/02 15:47:52 ...s/install/setting.go:23:PreloadSettings() [I] Custom path: /var/lib/gitea/custom
May 02 15:47:52 jammy gitea[2210]: 2023/05/02 15:47:52 ...s/install/setting.go:24:PreloadSettings() [I] Log path: /var/lib/gitea/log
May 02 15:47:52 jammy gitea[2210]: 2023/05/02 15:47:52 ...s/install/setting.go:25:PreloadSettings() [I] Configuration file: /etc/gitea/app.ini
May 02 15:47:52 jammy gitea[2210]: 2023/05/02 15:47:52 ...s/install/setting.go:26:PreloadSettings() [I] Prepare to run install page
May 02 15:47:52 jammy gitea[2210]: 2023/05/02 15:47:52 ...s/install/setting.go:29:PreloadSettings() [I] SQLite3 is supported
May 02 15:47:53 jammy gitea[2210]: 2023/05/02 15:47:53 cmd/web.go:220:listen() [I] [645130a9] Listen: http://0.0.0.0:3000
May 02 15:47:53 jammy gitea[2210]: 2023/05/02 15:47:53 cmd/web.go:224:listen() [I] [645130a9] AppURL(ROOT_URL): http://localhost:3000/
May 02 15:47:53 jammy gitea[2210]: 2023/05/02 15:47:53 ...s/graceful/server.go:62:NewServer() [I] [645130a9] Starting new Web server: tcp:0.0.0.0:3000 on PID: 2210
.......

If you don’t need Proxy you can access and configure Gitea on http://Server_IP:3000

Step 4: Configure Nginx Proxy

Install nginx on your system.

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;
    }
}

Replace git.example.com with your actual domain name for Git service.

Set correct domain name and restart nginx service.

sudo systemctl restart nginx

Step 5: Configure Gitea on Ubuntu

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

Set database authentication

On the first page, set the database connection:

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.

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.

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

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.

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

Similar Articles:

Cart

Your Cart is Empty

Back To Shop