Gitea Ubuntu Install Notes

gitea logo

Git with tea…

Gitea is a lightweight interface to Git written in Golang. It is easy to set up. Here are my notes for a simple install on an Ubuntu 20.04 server. I find them useful, I hope they may be of use to you.

Firstly. make sure you are using a static IP address. For the purpose of this post, I will use 192.168.1.11 and I’ll be using the MySQL database.

If you need help setting up a static IP address see here.

Let’s install some basic tools:

sudo apt-get install wget git

If you haven’t installed MySQL, download it and configure the root user:

sudo apt-get install mysql-server mysql-client libmysqlclient-dev -y

sudo mysql -u root

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'secret';

exit

sudo service mysql restart

Now we can set up the Gitea database:

mysql -u root -p

CREATE USER 'gitea' IDENTIFIED WITH mysql_native_password BY 'secret';

CREATE DATABASE gitea CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';

GRANT ALL PRIVILEGES ON gitea.* TO 'gitea';

FLUSH PRIVILEGES;

exit

We’ll need to get the latest version of Gitea, as of this post it is 1.12.5:

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

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

gitea --version

Next, we’ll set up a Git user and configure permissions:

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

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

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

sudo chmod -Rv 750 /var/lib/gitea/

sudo mkdir -v /etc/gitea

sudo chown -Rv root:git /etc/gitea/

sudo chmod -Rv 770 /etc/gitea

It’s time to configure the Gitea service:

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

Copy this into Vim, save and exit:

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

[Service]
LimitMEMLOCK=infinity
LimitNOFILE=65535
RestartSec=2s
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
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

Enable the service:

sudo systemctl start gitea

sudo systemctl status gitea

sudo systemctl enable gitea

If you are using ufw, allow the default port (3000) and the desired port 80. The desired port is what I will set in the configuration screen.

sudo ufw allow 3000/tcp

sudo ufw allow http

In your browser visit your Gitea site:

http://192.168.1.11:3000

Click Sign In, this will take you to the configuration page where you can customise and complete your installation.

Under Database Settings:

  • enter your Gitea password
  • set charset to utf8mb4

Under General Settings:

That’s all the settings I am interested in at the moment. I skip the Optional Settings completely, they are not needed for now.

When ready, click the Install Gitea button.

After a short delay, if you changed the port number like I did (to 80), you will get a “This site can’t be reached” error. In that case we’ll need to restart Gitea to use our new port – and we should update our ufw rules accordingly.

To remove the 3000 rule, look for the rule number and delete it:

sudo ufw status numbered

sudo ufw delete 5 

Restart Gitea:

sudo systemctl restart gitea

Now visit your Gitea home page and click Register.

http://192.168.1.11/

This first user you configure will be the default admin if you didn’t specify an admin earlier in the Optional Configuration settings.

That’s it, you should now be able to create your first repository.

For more information, with accompanying screen shots, please see this post which was the reference I worked from initially.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s