How to Install Gitea on Ubuntu Linux

|

|

This tutorial provides a step-by-step guide on how to install Gitea, a free and open-source version control platform on Ubuntu 20.04 | 18.04 LTS servers. The process involves the installation of Git and MariaDB, the creation of a Git user and a Gitea database, and the configuration of the Gitea service.

This brief tutorial shows students and new users how to install Gitea on Ubuntu 20.04 | 18.04 LTS servers.

Gitea is an open-source version control platform similar to Github. It’s probably the easiest, fastest, and painless way to set up a self-hosted Git service.

There are several reasons why you may want to install Gitea on Ubuntu Linux:

1. Self-hosted Git service: Gitea is a self-hosted Git service that allows you to manage your Git repositories on your servers. This gives you complete control over your code and data.

2. Open-source: Gitea is a free open-source platform that can be used and modified. This means that you can customize it to meet your specific needs.

3. Easy to install: Gitea is easy to install on Ubuntu Linux. With a few simple commands, you can quickly get Gitea up and running on your server.

4. Rich features: Gitea comes with rich features such as issues and time tracking, repository branching, file locking, tagging, merging, and many other features that you will find in a typical source control platform.

5. Project management tools: Gitea also has flexible project management tools that allow you to visualize, prioritize, coordinate, and track progress. This helps streamline your collaborative workflows and makes it easier to manage your projects.

Install Git and Create Git User

Before continuing below, run the command to install the git package on Ubuntu.

sudo apt update
sudo apt install git

After installing Git, run the commands below to create a Git user to run Gitea services. To do that, run the commands below

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

You should see a similar message below:

Output:
Adding system user `git' (UID 122) .
Adding new group `git' (GID 127) .
Adding new user `git' (UID 122) with group `git' .
Creating home directory `/home/git' .

Next, continue below and install MariaDB

Install MariaDB

Gitea requires a database server to store its content. And MariaDB is a great place to start looking for an open-source database server.

To install MariaDB, run the commands below.

sudo apt-get install mariadb-server mariadb-client

After installing MariaDB, the commands below can stop, start, and enable the service to start when the server boots.

Run these on Ubuntu 16.04 LTS

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

Run these on Ubuntu 18.10 and 18.04 LTS

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

After that, run the commands below to secure the MariaDB server by creating a root password and disallowing remote root access.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it. [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

Restart MariaDB server

Now that you’ve installed all the packages required for Gitea to function, continue below to start configuring the servers. First, run the commands below to create a blank Gitea database and database user.

To log on to the MariaDB database server, run the commands below.

sudo mysql -u root -p

Change the GLOBAL innodeb_file_per_table to On.

SET GLOBAL innodb_file_per_table = ON;

Then, create a database called giteadb

CREATE DATABASE giteadb;

Create a database user called giteauser with a new password

CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'new_password_here';

Then, grant the user full access to the database.

GRANT ALL ON giteadb.* TO 'giteauser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;

Next, run the commands below to update the database character set.

ALTER DATABASE giteadb CHARACTER SET = utf8mb4 COLLATE utf8mb4_unicode_ci;

Finally, save your changes and exit.

FLUSH PRIVILEGES;
EXIT;

Next, run the commands below to open the MariaDB default config file.

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

Then add the lines below and save.

innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic

Restart MariaDB after that.

sudo systemctl restart mariadb.service
sudo systemctl restart mysql.service

Continue below to download the Gitea package.

Install Gitea Packages

After creating the user account, run the commands below to download Gitea’s latest package. You can find its latest version from the link below:

https://github.com/go-gitea/gitea

Run the commands below to download version 1.8.0. You can replace the version number with the latest if it becomes available.

cd /tmp
wget https://dl.gitea.io/gitea/1.8.0/gitea-1.8.0-linux-amd64

After downloading the file, move it into the /usr/local/bin directory and make it executable.

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

Next, create this folder for Gitea to use, then update their permissions using the commands below.

sudo mkdir -p /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 mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

After that, run the commands below to create the Gitea systemd script.

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

Then copy and paste the content below into the file and save it.

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
#After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=redis.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

After that, reload systemd and start the Gitea service

sudo systemctl daemon-reload
sudo systemctl enable gitea
sudo systemctl start gitea

To check Gitea’s status, run the commands below:

sudo systemctl status gitea

You should see a similar message below

● gitea.service - Gitea (Git with a cup of tea)
   Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: en
   Active: active (running) since Fri 2019-04-26 10:52:32 CDT; 11s ago
 Main PID: 7118 (gitea)
    Tasks: 6 (limit: 4683)
   CGroup: /system.slice/gitea.service
           └─7118 /usr/local/bin/gitea web -c /etc/gitea/app.ini

Apr 26 10:52:32 ubuntu1804 gitea[7118]: 2019/04/26 10:52:32 [T] Log path: /var/l
Apr 26 10:52:32 ubuntu1804 gitea[7118]: 2019/04/26 10:52:32 [I] Gitea v1.8.0 bui
Apr 26 10:52:32 ubuntu1804 gitea[7118]: 2019/04/26 10:52:32 [I] Log Mode: Consol
Apr 26 10:52:32 ubuntu1804 gitea[7118]: 2019/04/26 10:52:32 [I] XORM Log Mode: C
Apr 26 10:52:32 ubuntu1804 gitea[7118]: 2019/04/26 10:52:32 [I] Cache Service En
Apr 26 10:52:32 ubuntu1804 gitea[7118]: 2019/04/26 10:52:32 [I] Session Service 
lines 1-18/18 (END)

Next, open your browser and browse to the server hostname or IP address followed by port 3000

http://localhost:3000/install

Type in the database connection info and continue with the setup.

Gitea Ubuntu setup

Set up the backend admin account as well.

Gitea Ubuntu setup

Login and enjoy!

After the installation, you should be able to log on and use Gitea as a git service.

Conclusion:

This post showed you how to install Gitea on Ubuntu 20.04 | 18.04. If you find any error above, please use the form below to report.

You may also like the post below:

Like this:



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.