In this article, we will have explained the necessary steps to install and configure Gogs on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
Gogs is an open source version control platform similar to Github. It’s lightweight, cross-platform, and easy to install, so you can easily set up a self-hosted git service in your development environment. Gogs is distributed as an independent binary distribution and has minimal requirements so it can run on all platforms that Go supports, such as Windows, Linux, ARM, Mac, etc.
Install Gogs on Ubuntu
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install and Configure MariaDB.
Gogs can use MariaDB, PostgreSQL, MSSQL, TiDB and SQLite3 databases for its database backend. In this tutorial, we will use MariaDB. Install the latest MySQL server by executing the following command:
sudo apt install mariadb-server git wget
When the MariaDB installation is complete, secure your MariaDB installation using the mysql_secure_installation script:
Log in to the MySQL console with the MySQL root user, using the password that you have set up in the previous step:
mysql -u root -p
Create a MySQL database and user for Gogs, and grant permissions to the user using the following commands:
mariadb> CREATE SCHEMA `gogs` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; mariadb> GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost' IDENTIFIED BY 'Your-Strong-Password'; mariadb> FLUSH PRIVILEGES; mariadb> \q
Step 3. Install Gogs.
First, create a new system user for Gogs:
sudo adduser --home /opt/gogs --shell /bin/bash --gecos 'Gogs application' gogs
The following commands will download the Gogs binary from the Gogs Github page:
sudo wget https://github.com/gogs/gogs/releases/download/v0.11.86/linux_amd64.tar.gz
Extract the archive to the /opt/gogs directory:
tar xvf linux_amd64.tar.gz --strip-components=1 -C /opt/gogs
Change the ownership of the directory to the Gogs user:
sudo chown -R gogs:gogs /opt/gogs/
Next, copy the systemd unit file:
sudo cp /opt/gogs/scripts/systemd/gogs.service /etc/systemd/system/
Open the unit file using your favorite text editor:
sudo nano /etc/systemd/system/gogs.service
Once the file is open, edit it as follows:
[Unit] [Unit] Description=Gogs After=syslog.target After=network.target After=mariadb.service mysqld.service postgresql.service memcached.service redis.service [Service] # Modify these two values and uncomment them if you have # repos with lots of files and get an HTTP error 500 because # of that ### #LimitMEMLOCK=infinity #LimitNOFILE=65535 Type=simple User=gogs Group=gogs WorkingDirectory=/opt/gogs ExecStart=/opt/gogs web Restart=always Environment=USER=gogs HOME=/opt/gogs # Some distributions may not support these hardening directives. If you cannot start the service due # to an unknown option, comment out the ones not supported by your version of systemd. ProtectSystem=full PrivateDevices=yes PrivateTmp=yes NoNewPrivileges=true [Install] WantedBy=multi-user.target
Save and close the file, then start and enable the Gogs service:
sudo systemctl daemon-reload sudo systemctl start gogs sudo systemctl enable gogs
Step 4. Install Gogs using the web installer.
Now that Gogs is downloaded and running, it is time to finalize the installation through the web interface. Open your browser, type http://YOUR_DOMAIN_IR_IP:3000 and fill in all of the required fields. Remember to replace “server_ip” with your server’s public IP address:
– Database Type: MySQL
– Host: 127.0.0.1:3306
– User: gogs
– Password: strongpassword
– Database Name: gogs
General Settings of Gogs
– Application Name: Gogs
– Repository Root Path: /opt/gogs/gogs-repositories
– Run User: gogs
– Domain: SERVER_IP
– SSH Port: 22
– HTTP Port: 3000
– Application URL: http://SERVER_IP:3000/
– Log Path: /opt/gogs/log
Finally, click install and you’re good to go.
That’s all you need to do to install Gogs on Ubuntu 18.04 Bionic Beaver. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.