How To Set Up Gogs on Ubuntu 14.04
How To Set Up Gogs on Ubuntu 14.04
We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Set Up Gogs on Ubuntu 14.04

PostedMarch 11, 2015 46.6k views Git

An Article from Gogs


Gogs is a self-hosted Git service written in Go which is very easy to get running and has low system usage as well. It aspires to be the easiest, fastest, and most painless way to set up a self-hosted Git service.

By the end of this tutorial, you will have a running instance of Gogs, which includes a web interface, an admin dashboard, and access to operations like Git pull and push.


To follow this tutorial, you will need:

  • An Ubuntu 14.04 Droplet of any size.
  • A sudo non-root user. In this tutorial, we'll use a separate sudo non-root user only for Gogs for security concerns. This tutorial assumes this dedicated user is named git, following the convention of the Git service; this tutorial should be followed as the git user.

Step 1 — Install the Database

In this step, we will create the back end Gogs database.

After you log in, make sure your system packages are up to date.

sudo apt-get update

We're going to use MySQL as our back end server, so next, install it. The -y flag here assumes yes to all prompts.

sudo apt-get -y install mysql-server

During the installation, you will be asked to enter the password of the database root user. Make sure you use a secure one, and remember it, because you'll need it later in this tutorial.

Now create and open a file named gogs.sql. Here, we're using nano, but you can use your favorite text editor.

nano gogs.sql

Paste the following contents into the file, and save and close it.


Finally, execute gogs.sql with MySQL to create the Gogs database. Replace your_password with the root password you chose earlier in this step.

Note: there is no space between the -p flag and your password in this command.

mysql -u root -pyour_password < gogs.sql

To install Gogs from source, version control tools like Git and Mercurial are needed, so install them next.

sudo apt-get -y install mercurial git

If you plan to clone a repository via SSH, a functioning SSH server is required, but fortunately, Ubuntu 14.04 comes with one out of the box.

Step 2 — Install Go

Because Gogs is written in Go, we need to install it before compiling Gogs.

First, there are some environment variables we need to set for Go. To do that, open the file ~/.bashrc for editing.

nano ~/.bashrc

Add the following lines to the end of the file, then close and save it.

export GOPATH=/home/git/go
export GOROOT=/usr/local/src/go
export PATH=${PATH}:$GOROOT/bin

Next, apply your changes.

source ~/.bashrc

Then use wget to download latest complied version of Go from its website. At the time of writing, the most recent file is go1.4.2.linux-amd64.tar.gz.


Use tar to unarchive it.

tar zxf go1.4.2.linux-amd64.tar.gz

Change directories to the $GOROOT we defined in ~/.bashrc.

sudo mv go $GOROOT

Now, if you type go in your terminal:


You should see something like this:

Go is a tool for managing Go source code.


    go command [arguments]


Use "go help [topic]" for more information about that topic.

Step 3 — Install and Start Gogs as a Service

Go has a built in command, get, for easily downloading the source code of a Go project along with all of its dependencies, which we'll use to download Gogs.

go get -d

The source code of Gogs will now be in $GOPATH/src/, so move there.

cd $GOPATH/src/

Next, build and generate the binary. This command may take a moment to run.

go build

We're going to use Supervisor to manage the Gogs service.

First, let's install it.

sudo apt-get -y install supervisor

Let's make a Gogs daemon by creating a Supervisor configuration section. First, create a directory for the log files to live in.

sudo mkdir -p /var/log/gogs

Next, we'll open the Supervisor configuration file for editing.

sudo nano /etc/supervisor/supervisord.conf

Append the following contents to the file to create the Gogs section.

command=/home/git/go/src/ web
environment = HOME="/home/git", USER="git"
user = git

This section defines the command we want to execute to start Gogs, automatically starts it with Supervisor, and specifies the locations of log files and corresponding environment variables. For more about Supervisor configuration, read this tutorial.

Now restart Supervisor.

sudo service supervisor restart

We can check that Gogs is running with the following command.

ps -ef | grep gogs

You should see something like this as the output.

root      1344  1343  0 08:55 ?        00:00:00 /home/git/go/src/ web

You can verify that the server is running by taking a look at the stdout.log file, too.

tail /var/log/gogs/stdout.log

You should see a line like this:

2015/03/09 14:24:42 [I] Gogs: Go Git Service Beta

You should also be able visit the web page with URL http://your_server_ip:3000/. This will redirect to the installation page, but don't fill that out just yet.

Step 4 — Set Up Nginx as a Reverse Proxy

Let's move on to configuring Nginx as a reverse proxy so you can easily bind a domain name to Gogs.

First, install Nginx.

sudo apt-get -y install nginx

Next, create an Nginx configuration file for gogs.

sudo nano /etc/nginx/sites-available/gogs

Add the following content, replacing your_server_ip with your Droplet's IP address. If you're using a domain name for your Droplet, you can use your domain name here instead.

server {
    listen 80;
    server_name your_server_ip;

    proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP

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

And symlink it so that Nginx can use it.

sudo ln -s /etc/nginx/sites-available/gogs /etc/nginx/sites-enabled/gogs

For more about Nginx virtual host configuration files, see this tutorial.

Finally, restart Nginx to activate the virtual host configuration.

sudo service nginx restart

You should now be able visit the web page with the URL http://your_server_ip/, without specifying the port.

Step 5 — Initialize Gogs

There is one more simple step left to initialize Gogs for its first run.

Visit http://your_server_ip/install and fill in the following options. Many of them will be filled out for you already, but make sure to replace the variables in red with the values for your server.

In the first section, Gogs requires MySQL, PostgreSQL or SQLite3, fill out:

  • Database Type: MySQL
  • Host:
  • User: root
  • Password: your_database_password
  • Database Name: gogs

In the second section, General Settings of Gogs, fill out:

  • Repository Root Path: /home/git/gogs-repositories
  • Run User: git
  • Domain: your_server_ip
  • HTTP Port: 3000
  • Application URL: http://your_server_ip/

Skip the optional e-mail and notification settings, then under Admin Account Settings, choose an admin username and password, and include your email address. We'll refer to the admin username as your_admin_username in the next step.

Finally, click Install Gogs, and then log in.

Step 6 — Test Gogs

You're all done! Let's do a simple pull/push test just to make sure Gogs is functioning correctly.

First, go to http://your_server_ip/repo/create and create a repository with the name my-test-repo, and you click on the option Initialize this repository with a

Now you should be able to clone it. First, move to your home directory.


Next, clone the repository.

git clone http://your_server_ip/your_admin_username/my-test-repo.git

Change to the repository directory.

cd my-test-repo

Update the

echo 'I love Gogs!' >>

Commit your changes and push them. This command will ask you for your Gogs username and password.

git add --all && git commit -m "init commit" && git push origin master


Now, if you go back to http://your_server_ip/your_admin_username/my-test-repo, you'll see the "I love Gogs!" line appended to the README. It's that easy!


Creative Commons License