Gogs is a painless self-hosted Git service that allows you to create, fork, and edit repositories, manage user access, and more. In this tutorial, we will guide you through the process of installing Gogs on your Ubuntu server.
First, connect to your Ubuntu server via SSH, and update the package list and upgrade the system using the following command:
sudo apt update && sudo apt upgrade -y
Gogs is built on top of Git, so you need to install Git on your Ubuntu server using the following command:
sudo apt install git -y
To run Gogs, you need to have a dedicated user account. The following command creates a new user named git
:
sudo adduser --system --group --shell /bin/bash --disabled-password --home /home/git git
Gogs needs to store its data on a database, so you need to install one.
For this tutorial, we will be using MariaDB, which is a fork of MySQL.
Run the following command to install MariaDB:
sudo apt install mariadb-server -y
After installation, start the MariaDB service and enable it to start on boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Run the following command to secure the MariaDB installation:
sudo mysql_secure_installation
Follow the prompts, and enter a secure password for the root user.
Create a new database for Gogs:
sudo mysql -u root -p
Enter the password for the root user, then run the following commands to create a new database and grant user privileges:
CREATE DATABASE gogs_db;
CREATE USER 'gogs_user'@'localhost' IDENTIFIED BY 'your_password_here';
GRANT ALL PRIVILEGES ON gogs_db.* TO 'gogs_user'@'localhost';
FLUSH PRIVILEGES;
exit;
Create a new directory /opt/gogs
:
sudo mkdir -p /opt/gogs
Change the directory to /opt/gogs
:
cd /opt/gogs
Download the latest version of Gogs using the following command:
sudo wget $(curl -s https://api.github.com/repos/gogs/gogs/releases/latest | grep browser_download_url | grep linux_amd64 | cut -d '"' -f 4)
Extract the downloaded file:
sudo tar -xvf gogs*
Change the owner of the extracted directory:
sudo chown -R git:git /opt/gogs
Copy the sample configuration file:
sudo cp /opt/gogs/custom/conf/app.ini.sample /opt/gogs/custom/conf/app.ini
Edit the configuration file:
sudo nano /opt/gogs/custom/conf/app.ini
Paste in the following settings:
APP_NAME = Gogs
RUN_USER = git
RUN_MODE = prod
[database]
DB_TYPE = mysql
HOST = 127.0.0.1:3306
NAME = gogs_db
USER = gogs_user
PASSWD = your_password_here
SSL_MODE = disable
CHARSET = utf8
Save and close the file.
Create a new systemd service file for Gogs using the following command:
sudo nano /etc/systemd/system/gogs.service
Paste the following configuration:
[Unit]
Description=Gogs
After=syslog.target
After=network.target
[Service]
LIMITNOFILE=5000
User=git
Group=git
WorkingDirectory=/opt/gogs/
ExecStart=/opt/gogs/gogs web
Restart=always
Environment=USER=git HOME=/home/git GOGS_CUSTOM=/opt/gogs/custom
[Install]
WantedBy=multi-user.target
Save and close the file.
Start and enable the Gogs service:
sudo systemctl start gogs
sudo systemctl enable gogs
Configure the firewall to allow traffic to the Gogs web service:
sudo ufw allow 22/tcp
sudo ufw allow 3000/tcp
sudo ufw enable
Open your web browser and enter your server's IP address or domain address followed by port 3000
, like this:
http://your_domain_or_server_ip:3000/
You should see the Gogs web interface. Follow the prompts to set up your Gogs administrator account.
You have successfully installed Gogs on your Ubuntu server. You can now create repositories, invite team members, manage user access, and more. Happy coding!
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!
Alternatively, for the best virtual desktop, try Shells!