In this tutorial, we’ll install and configure Gogs on CentOS Linux.
What is Gogs?
Gogs is a self-hosted Git service that provides much of the functionality of Github. It is written in Go, and is available as a single binary.
Before you install it, you can try a demo of Gogs.
Installation of Gogs
In this tutorial, we will install Gogs in /opt/gogs, and will use MariaDB as the database.
1. Install MariaDB
First – you will need a database server – Install MariaDB on your CentOS Linux instance.
2. Create database
You’ll also need to create a database, and database username & password. It’s important to create this database with the utf8-mb4 character set.
You can use this tutorial to create the database.
3. Add a gogs user
useradd -d /opt/gogs gogs
4. Create gogs repository parent directory
5. Download Gogs
At the time of writing, the latest version of Gogs is 0.11.29
wget https://cdn.gogs.io/0.11.29/linux_amd64.tar.gz -O /opt/gogs.tar.gz
6. Extract Gogs & set ownership
cd /opt/ && tar xzvf gogs.tar.gz
chown -R gogs:gogs /opt/gogs chown gogs:gogs /opt/gogs-repositories
For setup purposes, start Gogs manually, as the gogs user:
su -c '/opt/gogs/gogs web' gogs
Gogs should now be running. Connect to it in your browser via http://<GOGS_IP>:3000/, you should be greeted with the Gogs installation/setup screen.
Enter the database credentials that you created in Step 2.
Application General Settings
Set the Repository Root Path to /opt/gogs-repositories
Set Run User to ‘gogs’
Set the domain to the DNS name of the Gogs instance, ie. git.centosblog.com
Application URL – for set up, set it to http://<GOGS_IP>:3000/
Email Service and Server and Other Settings
Some of these settings are optional – configure as necessary to your set up here.
Admin Account Settings
Set your initial admin user account here, the username must be something else other than “admin”.
When all your settings are set, Click ‘Install Gogs’
Once Gogs has been installed, it will persist settings to /opt/gogs/custom/conf/app.ini – you can change Gogs settings directly by editing this file.
Now that we have set up Gogs interactively, CTRL+C the running instance of it so that we can set it up as a service.
8. Gogs systemd service
Note: the following systemd file has been adapted from the default systemd service file provided with Gogs.
[Unit] Description=Gogs After=network.target After=mariadb.service [Service] Type=simple User=gogs Group=gogs WorkingDirectory=/opt/gogs ExecStart=/opt/gogs/gogs web Restart=always RestartTimeout=30 Environment=USER=gogs HOME=/opt/gogs [Install] WantedBy=multi-user.target
Enable Gogs and start the service:
systemd enable gogs && systemd start gogs
Gogs should now be up and running as a service!
I would strongly suggest that you configure Gogs to run behind an HTTPS reverse proxy. When do you configure Gogs behind a reverse proxy, you will need to be sure to update the domain and application URL in the Gogs configuration file (/opt/gogs/custom/conf/app.ini) so that URLs and links will be correct.
For example, if you choose to run Gogs behind an HTTPS reverse proxy configured at https://git.centosblog.com/ you will need to update your domain to “git.centosblog.com” and your application URL to “https://git.centosblog.com/”