12th September, 2016 | Tutorials |

How to Install Gogs on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.

Get a Cloud Server

Gogs is a self-hosted git service, similar to Gitlab. It is written in Go and requires much less hardware compared to Gitlab. The goal of Gogs is to provide the easiest, fastest, and most painless way of setting up a self-hosted Git service. As this application is written in Go, it supports all platforms like Linux, Windows, OS X and ARM.

Features of Gogs:


Gogs supports many operating systems but in this tutorial we are going to install Gogs in CentOS 7.x.


Apart from this we will need to install all the required dependencies in the tutorial. Additionally you can always increase the CPU cores and memory to add support for more users.

You can use the IP address of your server to install and set up Gogs, but it is recommended to use a FQDN. In this tutorial we will be using To use a domain name with Gogs, make necessary DNS changes to point your domain or subdomain to the IP address of your server. You will also need root access to your server. If you are logged in as non root user, run sudo -i to switch as root user.

Install Gogs

Gogs requires few dependencies in order to work, which are an SQL server, git and SSH server. We can use either MySQL or PostgreSQL server as SQL server. It also supports SQLite but SQLite is not recommended for production use. In this tutorial we will be installing MySQL.

Before installing any package it is recommended to update your system and packages. Run the following command to update your system.

    yum -y update

Now setup the hostname for your server. For the ease of identification, you may want it to be same as your domain name.

    hostnamectl set-hostname

You can replace with anything you want. You will also need to disable your SELinux. Run the following command to do so.

    sed -i /etc/selinux/config -r -e 's/^SELINUX=.*/SELINUX=disabled/g'

You will need to reboot your server for SELinux changes to take effect. Run systemctl reboot to reboot your server.

Install and setup MySQL

MySQL does not comes with the default YUM repository of CentOS, hence you will need to add the MySQL repository in your server. The following commands will add MySQL repositories in your server.

    rpm -ivh mysql57-community-release-el7-8.noarch.rpm
    yum -y update

Now install MySQL server on your machine using the following command.

    yum -y install mysql-server

Now start MySQL server and enable it to automatically start at boot time using following commands.

    systemctl start mysqld
    systemctl enable mysqld

During installation the root user of MySQL is assigned a random password. To fetch the password run the following command.

    grep 'temporary password' /var/log/mysqld.log

You will see an output similar to the one shown below. The output should contain your temporary root password.

    [root@git ~]# grep 'temporary password' /var/log/mysqld.log
    2016-09-10T07:24:29.105209Z 1 [Note] A temporary password is generated for root@localhost: i,DtiXeP!1EG

Now you will need to secure your MySQL installation using the following command.


You will be asked for your MySQL root password. Enter your temporary password. Once logged in, change the password for root user. You will be prompted with few more questions. Recommended is that you answer y for all questions. The output will look like shown below.

    [root@git ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root.

Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y

New password:

Re-enter new password:

Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y Success.

All done!

Now login to your MySQL command line using the following command and providing your new MySQL root password.

    mysql -u root -p

Then execute the following queries in MySQL command line.

    use gogs;
    SET default_storage_engine=INNODB;

You will see following output for these commands.

    [root@git ~]# mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 14
    Server version: 5.7.15 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.00 sec)

mysql> use gogs; Database changed mysql> SET default_storage_engine=INNODB; Query OK, 0 rows affected (0.00 sec)

mysql>exit Bye

As we have our database ready, we can now move to next step.

Install Git

Gogs required to git for version control, you can get git using the following command.

    yum -y install git

You can check your Git version using the following command.

    git --version

You should get similar output.

    [root@git ~]# git --version
    git version

Install Gogs

You can install Gogs in many different ways but the easiest way to install Gogs is using Packager Repository. Run the following commands to add Gogs repository in your server.

    rpm --import
    echo "[gogs]
    name=Repository for pkgr/gogs application.
    enabled=1" | tee /etc/yum.repos.d/gogs.repo

Now you can install Gogs, using the following command.

    yum -y install gogs

Once the installation finishes you can starts Gogs using the following command.

    systemctl start gogs

To enable Gogs to start at boot time, run the following command.

    systemctl enable gogs

To check the status of Gogs service, run the following command.

    systemctl status gogs

If service is running you will get output similar to shown below.

    [root@git ~]# systemctl status gogs
    ● gogs.service
       Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: disabled)
       Active: active (running) since Sat 2016-09-10 08:34:53 UTC; 6min ago
     Main PID: 5760 (sleep)
       CGroup: /system.slice/gogs.service
               └─5760 /bin/sleep infinity

Sep 10 08:34:53 systemd[1]: Started gogs.service. Sep 10 08:34:53 systemd[1]: Starting gogs.service... Sep 10 08:36:56 systemd[1]: Started gogs.service.

By default Gogs service runs on port 3000, you can access the web installer for Gogs on http://your-server-IP:3000 or Please do not make any changes to this page as we are going to run nginx as the reverse proxied web server, and Gogs web server will run behind the scenes.

Install and Configure Nginx

Nginx does not come with the default YUM repository, hence you will need to add EPEL repository to your server. Run the following command to do so.

    yum -y install epel-release
    yum -y update
    yum clean all

Now you can install nginx using the following command.

    yum -y install nginx

Now start nginx and enable it start at boot time using the following command.

    systemctl start nginx
    systemctl enable nginx

Now you will need to create a virtual host file for your nginx reverse proxy.

    mkdir /etc/nginx/conf.d
    nano /etc/nginx/conf.d/gogs.conf

You can also use any editor of your choice. Put the following content in the new file.

    server {
        listen 80;
        server_name your_domain_or_server_ip;

proxy_set_header X-Real-IP $remote_addr;

location / { proxy_pass http://localhost:3000; } }

Replace your_domain_or_server_ip with your domain or the server IP. You can also put your domain name and IP address both, separated by a space to enable the access using both domain name and IP address.

Now restart your nginx server using the following command.

    systemctl restart nginx

Now you will be able to access the site by browsing the following URL using your favorite browser. If you are using your domain name name then your site is accessible on if you are using IP address, then it will be accessable on http://your-IP-address

If you wish to use HTTPS instead of Plain HTTP, you can either generate a self signed certificate or purchase a commercial SSL certificate. You can also use Certbot or Let's Encrypt SSL to generate free SSL for your domain.

Download Certbot script using the following command.

    chmod +x certbot-auto 
    mv certbot-auto /usr/bin/certbot-auto

Now we can directly run certbot-auto from terminal. Before we can generate SSL to use with nginx we will need to stop nginx server. Run the following command for same.

    systemctl stop nginx

To generate a SSL certificate for your domain run the following command.

    certbot-auto certonly --standalone -d

Replace with your domain name. To generate SSL for your domain, you must have the DNS configured which points your domain to the IP address of the server. If you do not have your domain configured, you can stay with HTTP also.

You will be asked to enter your email address and accept the terms and conditions. Finally you will see message similar to this.

    [root@ip-172-31-17-38 ~]# certbot-auto certonly --standalone -d

IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/ Your cert will expire on 2016-12-09. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: Donating to EFF:

Once done you can configure nginx to use SSL certificates by editing the virtual host configuration file using the following command.

    nano /etc/nginx/conf.d/gogs.conf

Now replace the existing contents with the new content shown below.

    server {
        listen 80;
        return 302 https://$server_name$request_uri;

server { listen 443 ssl; server_name;

ssl_certificate /etc/letsencrypt/live/; ssl_certificate_key /etc/letsencrypt/live/;

location / { proxy_set_header X-Real-IP $remote_addr; proxy_pass http://localhost:3000; } }

Replace with your domain name and also change the path of SSL certificates as required. Once done start your nginx server using the following command.

    systemctl start nginx

Installation Using Web Installer

Now you can browse your site on Once you browse your site you will see following screen.

HP_NO_IMG/data/uploads/users/166e68d1-e927-457c-b7b0-14eca571ad0c/2072759490.png" alt="" />

In Database Setting choose the database type, in this case it will be MySQL. The host should not be changed, and as we have used root user to create MySQL database, the user should be root. Enter the password of your MySQL root user. Database name should also be left as gogs.

HP_NO_IMG/data/uploads/users/166e68d1-e927-457c-b7b0-14eca571ad0c/1936675182.png" alt="" />

In Application General Settings, provide a name for your Application, you can give the name of your organisation. Provide a path for your repositories. You can choose to leave it as it is or you can also change the path as required. Make sure that the directory is under Gogs home directory which is /home/gogs/. All the git remote repositories will be saved here.

HP_NO_IMG/data/uploads/users/166e68d1-e927-457c-b7b0-14eca571ad0c/1672400379.png" alt="" />

In Run As option choose the user which runs Gogs, also has access to the repository root path. In our case, it should be left as gogs. Now provide the domain name for your repository. This domain name will be used when cloning via SSH. Do not include http:// or www in this domain name. Provide a port for SSH, it should be left as 22 unless changed. Provide a port on which the application will listen, it should be left as 3000. Now provide the HTTP Application url of your Git server. It should be in format. Choose a path to store the logs.

Furthermore you can configure the SMTP settings to that Gogs can send email notification to the user. If you do not have SMTP credentials you can skip this configuration.

In Admin Account Settings, provide a username for administrator, it must be something other than admin. Provide the password for the administrator account twice and provide a email for admin account.

HP_NO_IMG/data/uploads/users/166e68d1-e927-457c-b7b0-14eca571ad0c/409177929.png" alt="" />

Finally click on Install Gogs button to launch the web installer. Once the installation finishes you will be automatically logged into the dashboard.

HP_NO_IMG/data/uploads/users/166e68d1-e927-457c-b7b0-14eca571ad0c/1069908171.png" alt="" />

Using Gogs

Once you are logged in you can create repository by click on Add icon and selecting New Repository option.

HP_NO_IMG/data/uploads/users/166e68d1-e927-457c-b7b0-14eca571ad0c/192675749.png" alt="" />

In New Repository interface, provide the required information and press Create Repository button.

HP_NO_IMG/data/uploads/users/166e68d1-e927-457c-b7b0-14eca571ad0c/451149524.png" alt="" />

Once the repository has been created you will be taken to the dashboard for your new repository.

From here you can see the URL by which the repository can be cloned anywhere. You can also clone it on your system by running the following command.

    git clone

Change the Repository URL according to the URL generated.

HP_NO_IMG/data/uploads/users/166e68d1-e927-457c-b7b0-14eca571ad0c/1553695210.png" alt="" />

From the dashboard you can create a new file or upload an existing file into the repository. You can also edit the files using the web based interface by clicking on the name of the file.


In this tutorial we have learnt to install Gogs on CentOS 7.x, You can now easily host a private Git repository on your server even if do not have huge resources. You can also easily create repositories and collaborate with others. If you want more features then Gogs provides, you can install GitLab on your CentOS server.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.

Get a Cloud Server