How to Install Gitea on FreeBSD Latest
Gitea is a self-hosted Git service that is a lightweight alternative to other Git services like GitHub or GitLab. In this tutorial, we will go through the steps to install Gitea on FreeBSD Latest.
Prerequisites
Before we start with the installation of Gitea, make sure that your FreeBSD system is up-to-date and has the necessary dependencies installed. Additionally, you will need to have the sudo privileges to install and configure the service.
sudo pkg update && sudo pkg upgrade
sudo pkg install bash mysql57-server git go
Step 1: Create a MySQL Database
Gitea requires a MySQL database to store its data. We will create a new database and user for Gitea. Open the MySQL shell and enter the following commands to create a new database and user.
sudo mysql -u root
CREATE DATABASE gitea;
CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost';
FLUSH PRIVILEGES;
Change 'password' to a strong password that you can remember.
Step 2: Install Gitea
We will download and install the latest version of Gitea from their official website. Go to the following URL to see the latest version: https://gitea.io/en-us/download/
cd /usr/local
sudo fetch https://dl.gitea.io/gitea/1.15.4/gitea-1.15.4-freebsd-amd64.tar.gz
sudo tar -zxf gitea-1.15.4-freebsd-amd64.tar.gz
sudo mv gitea-1.15.4-freebsd-amd64 gitea
Change the '1.15.4' version to the latest version available.
Step 3: Configure Gitea
We will create a new system user for Gitea and configure Gitea to run with this user.
sudo pw user add gitea -c "Gitea User" -d /nonexistent -s /usr/bin/false
sudo chown -R gitea:gitea /usr/local/gitea
sudo su - gitea
./gitea web --config /usr/local/gitea/custom/conf/app.ini
This will start the Gitea server, which will be accessible at http://localhost:3000/
Step 4: Configure Gitea as a System Service
We will configure Gitea as a system service so that it starts automatically when the system is restarted.
sudo su -
cat <<EOF > /usr/local/etc/rc.d/gitea
#!/bin/sh
# PROVIDE: gitea
# REQUIRE: LOGIN mysql
# KEYWORD: shutdown
. /etc/rc.subr
name="gitea"
rcvar="gitea_enable"
load_rc_config "\$name"
: "\$gitea_enable" == "YES" && command="/usr/local/gitea/gitea"
: "\$gitea_enable" == "NO" && exit 0
command_args="web --config /usr/local/gitea/custom/conf/app.ini"
pidfile="/var/run/\${name}.pid"
command_interpreter="/usr/local/bin/bash"
start_cmd="gitea_start"
stop_cmd="gitea_stop"
restart_cmd="gitea_restart"
gitea_start() {
rm -f \${pidfile}
su -m gitea -c "nohup \${command} \${command_args} > /dev/null 2>&1 & echo \$! > \${pidfile}"
}
gitea_stop() {
pkill -f gitea
rm -f \${pidfile}
}
gitea_restart() {
gitea_stop
sleep 1
gitea_start
}
run_rc_command "\$1"
EOF
chmod 755 /usr/local/etc/rc.d/gitea
Step 5: Start and Enable the Gitea Service
Start and enable the Gitea service to run automatically at system startup.
sudo sysrc gitea_enable="YES"
sudo service gitea start
Verify that the service is running by accessing the Gitea site at http://localhost:3000/
Congratulations! You have successfully installed Gitea on FreeBSD Latest. You can now start using it as your self-hosted Git service.