Gitea is the fastest and most painless self-hosted Open source Git Service. Gitea is written in Go and distributed as a binary package that runs across all platforms and architectures that Go supports – Linux, macOS, and Windows. In this guide, we’ll install and configure Gitea Git Service on Debian 11| Debian 10 Linux.
Gitea Key Features
- Free and Open source
- Has low resource usage – both RAM and CPU
- Multiple database support
- Markdown and Orgmode support
- Integrated Git-powered wiki
- Repository Tokens with write rights
- External git mirroring
- Git LFS 2.0
- Granular user roles (Code, Issues, Wiki etc)
- GPG Signed Commits
- Web Code editor
- Commit graph
- Issue search & Issue tracker
- Restrict push and merge access to certain users
- Webhook support
- Multiple LDAP / AD server support
- LDAP user synchronization
- Two factor authentication (2FA)
- OpenId Connect support
- OAuth 2.0 integration (external authorization)
- Mattermost/Slack integration
- Microsoft Teams integration
- External CI/CD status display
- and many others
In this tutorial, we’ll do installation of Gitea on Debian 11| Debian 10 Linux and configure Nginx proxy to forward requests to Gitea internal service on a port. With Nginx, you can optionally terminal SSL certificates when doing a secure setup on Gitea on Debian 10 Server.
Step 1: Update System and Install git
You need to have git installed in your Debian machine. Let’s update our OS and ensure git is installed.
sudo apt -y update
sudo apt -y install git vim bash-completion
View the version of Git installed.
$ git --version
git version 2.30.2
Step 2: Add git user account for Gitea
Gitea should have a dedicated local user account for management operations. Add the user and group to your Debian system by running the following commands.
sudo adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
git
The user creation will assign a unique ID for the user and create its home directory.
Adding system user `git' (UID 108) ...
Adding new group `git' (GID 114) ...
Adding new user `git' (UID 108) with group `git' ...
Creating home directory `/home/git' ...
Step 3: Install MariaDB database server
Data will be stored on MariaDB database server.
sudo apt -y install mariadb-server
Secure your database installation by setting root password and removing test database and users.
$ sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Create a database for Gitea.
$ sudo mysql -u root -p
CREATE DATABASE gitea;
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY "StrOngPassw0rd";
FLUSH PRIVILEGES;
QUIT;
Step 4: Install Gitea on Debian 11 / Debian 10
The gitea binary packages are available on 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/bin
chmod +x gitea-*-linux-amd64
sudo mv gitea-*-linux-amd64 /usr/local/bin/gitea
Confirm successful installation by checking the version of Gitea installed.
$ gitea --version
Gitea version 1.19.2 built with GNU Make 4.1, go1.20.3 : bindata, sqlite, sqlite_unlock_notify
Step 5: Configure Systemd for Gitea
Create directories required for Gitea setup.
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 file for Gitea.
sudo vim /etc/systemd/system/gitea.service
Configure the file and set User, Group and WorkDir.
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
After=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 -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
[Install]
WantedBy=multi-user.target
Reload systemd and restart Gitea service.
sudo systemctl daemon-reload
sudo systemctl enable --now gitea
Check service status.
$ 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:54:09 UTC; 3s ago
Main PID: 2470 (gitea)
Tasks: 7 (limit: 4553)
Memory: 119.1M
CPU: 762ms
CGroup: /system.slice/gitea.service
└─2470 /usr/local/bin/gitea web -c /etc/gitea/app.ini
May 02 15:54:09 debian11 gitea[2470]: 2023/05/02 15:54:09 ...s/install/setting.go:21:PreloadSettings() [I] AppPath: /usr/local/bin/gitea
May 02 15:54:09 debian11 gitea[2470]: 2023/05/02 15:54:09 ...s/install/setting.go:22:PreloadSettings() [I] AppWorkPath: /var/lib/gitea
May 02 15:54:09 debian11 gitea[2470]: 2023/05/02 15:54:09 ...s/install/setting.go:23:PreloadSettings() [I] Custom path: /var/lib/gitea/custom
May 02 15:54:09 debian11 gitea[2470]: 2023/05/02 15:54:09 ...s/install/setting.go:24:PreloadSettings() [I] Log path: /var/lib/gitea/log
May 02 15:54:09 debian11 gitea[2470]: 2023/05/02 15:54:09 ...s/install/setting.go:25:PreloadSettings() [I] Configuration file: /etc/gitea/app.ini
May 02 15:54:09 debian11 gitea[2470]: 2023/05/02 15:54:09 ...s/install/setting.go:26:PreloadSettings() [I] Prepare to run install page
May 02 15:54:10 debian11 gitea[2470]: 2023/05/02 15:54:10 ...s/install/setting.go:29:PreloadSettings() [I] SQLite3 is supported
May 02 15:54:10 debian11 gitea[2470]: 2023/05/02 15:54:10 cmd/web.go:220:listen() [I] [64513222-2] Listen: http://0.0.0.0:3000
May 02 15:54:10 debian11 gitea[2470]: 2023/05/02 15:54:10 cmd/web.go:224:listen() [I] [64513222-2] AppURL(ROOT_URL): http://localhost:3000/
May 02 15:54:10 debian11 gitea[2470]: 2023/05/02 15:54:10 ...s/graceful/server.go:62:NewServer() [I] [64513222-2] Starting new Web server: tcp:0.0.0.0:3000 on PID: 2470
If you don’t need Nginx Proxy access Gitea using URL – http://server_ip_address:3000
Step 6: Configure Nginx proxy (Optional but recommended)
Install nginx on Debian 10.
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;
}
}
Set correct domain name and restart nginx service.
sudo systemctl restart nginx
Step 7: Finish Gitea Installation from Web interface
After configuring Nginx proxy, access Gitea web interface on http://git.example.com, replace git.example.com with your Gitea domain name.
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.
You can optionally create an admin user account. By default, 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 Debian 11| Debian 10 server. Refer to Gitea Documentation for advanced configurations and usage guides.
More git related guides.