This guide will go through how to install Gitea Code Hosting Service on Debian Linux. Gitea is a community-managed lightweight code hosting solution written in Go and published under the MIT license. It is a straightforward self-hosted Git service, comparable to GitHub, Bitbucket, and GitLab.
How to Install Gitea Code Hosting Service on Debian Linux
- Update your Debian system packages.
sudo apt update
- Then install dependencies for Gitea.
sudo apt install git wget mariadb-server
- Next, secure the MySQL database by running the command below.
sudo mysql_secure_installation
Sample output
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 haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] n ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. 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 Gitea database user
- Run the command below to log in to the MySQL database console.
sudo mysql -u root -p
- Then create the database.
CREATE DATABASE gitea;
- Next, create a database user with your preferred password as in the example below.
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY "YourStrongPassword";
- Flush all privileges.
FLUSH PRIVILEGES;
- Exit the MySQL console.
exit
Install Gitea Code Hosting Service on Debian Linux
- Navigate to the Gitea download page to get the latest release and then download it using
wget
command as shown below.
sudo wget -O /usr/local/bin/gitea https://dl.gitea.io/gitea/1.17.3/gitea-1.17.3-linux-amd64
- Change downloaded file permission.
sudo chmod +x /usr/local/bin/gitea
- To check the Gitea version use the following command.
gitea --version
- Next, create a git user using the command below.
sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git
- Create Gitea directories.
sudo mkdir -pv /var/lib/gitea/{custom,data,log}
- Change Gitea directories ownership.
sudo chown -Rv git:git /var/lib/gitea
- Modify main directory permissions.
sudo chmod -Rv 750 /var/lib/gitea
- Then create a configuration directory.
sudo mkdir -v /etc/gitea
- Change the created directory ownership.
sudo chown -Rv root:git /etc/gitea
- Change permissions.
sudo chmod -Rv 770 /etc/gitea
Create Systemd service file for Gitea
- Create a Systemd service file.
sudo nano /etc/systemd/system/gitea.service
Then paste the content below inside the created file. Save and close it.
[Unit] Description=Gitea After=syslog.target After=network.target [Service] RestartSec=3s 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 [Install] WantedBy=multi-user.target
- Start Gitea and enable it to start on system boot.
sudo systemctl enable --now gitea
Access Gitea Web Interface
- Open your web browser and enter your server IP or domain name followed by port 3000 e.g.
http://127.0.0.1:3000
. Enter your Gitea database name and password.
- Scroll down and click on the Install Gitea button.
- You will be taken to the home page where you can log in or create an account after the installation.
- That concludes our article on how to install Gitea Code Hosting Service on Debian Linux.
Read more on Gitea Documentation