How To Set Up Gogs on Ubuntu 14.04

Published on March 11, 2015
How To Set Up Gogs on Ubuntu 14.04

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.

wget https://storage.googleapis.com/golang/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 github.com/gogits/gogs

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

cd $GOPATH/src/github.com/gogits/gogs

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/github.com/gogits/gogs/gogs 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/github.com/gogits/gogs/gogs 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 README.md.

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 README.md.

echo 'I love Gogs!' >> README.md

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!

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Default avatar

staff technical writer

hi! i write do.co/docs now, but i used to be the senior tech editor publishing tutorials here in the community.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!


You should use the git user in Supervisor gogs configuration section instead of root user.


In 14.04, you can also use a new file, let’s say /etc/supervisor/conf.d/gogs.conf, it’s easier to manage.


Thanks for the tutorial, i did it some times ago and it was perfect :)

But I have a question, how do you update gogs ?

Thanks :)

Every time I restart the superuser, I get the following error:

Restarting supervisor: Error: Invalid user name git For help, use /usr/bin/supervisord -h

Does anyone know, what is going wrong?

Can we get a 1 click app for Gogs? GitLab is nice, but it’d be nice to have an alternative like Gogs as well. Thanks!



i’ve got a question, after i ran the commands above, all of the folders inside /home/git changed ownership to root:root. eventhough when i check with (ps aux) command the command gogs web is run by git. is it supposed to be that way or is it supposed to stay owned by git:git?

It looks like it works. The front interface is fully usable. Repo are created, it is fast, but… after creating a user on the gogs front and added the SSHKEY to it, a basic :

git clone git@myserver.com:gabrielstuff/test.git

return a password prompt… And none password work… Normally it should just clone it.

Any help would be much appreciated.

Hello, When I tried to push or make clone I got :

git@IP_SERVER's password: 

Why ? when I put the password it says :

fatal: 'kouceyla/qard-hasan.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.



First: thanks for a great tutorial!

I have some trouble cloning a repo. I get a

fatal: ‘hermanolsson/my-test-repo.git’ does not appear to be a git repository fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

error. When entering the full path /home/git/gogs-repositories/herm… it works fine. The gogs admin interface says ‘/home/git/gogs-repositories’ as the repository root path.

Any ideas on how to solve this?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel