Install GitBucket on Ubuntu 16.04

In this article, we will explain how to install GitBucket on an Ubuntu 16.04 VPS with Nginx as a reverse proxy. GitBucket is a Git platform powered by Scala with Github API compatibility. Some of the main features include public and private Git repositories, plug-in system, wiki, online editor, notifications …etc. This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 16.04 VPS.

Login to your VPS via SSH

ssh user@vps_IP

Update the system and install necessary packages

[user]$ sudo apt-get update && sudo apt-get -y upgrade
[user]$ sudo apt-get install software-properties-common git nano wget

Install Java 8

To add the webupd8team repository to your sources list and install the latest Oracle Java 8 JDK, run the following commands:

[user]$ sudo add-apt-repository ppa:webupd8team/java
[user]$ sudo apt-get update
[user]$ sudo apt-get install oracle-java8-installer

To check if JAVA has been properly installed on your Ubuntu 16.04 VPS run java -version, and the output should be similar to the following:

[user]$ java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Install GitBucket

Create a new GitBucket user:

[user]$ sudo adduser --gecos 'Gitbucket User' gitbucket

GitBucket will store all the git repositories in the home directory of the user who will launch the application.

Download latest gitbucket.war from Github. At the time of writing, the latest version is version 4.4.

[user]$ sudo wget -O /home/gitbucket/gitbucket.war https://github.com/gitbucket/gitbucket/releases/download/4.4/gitbucket.war
[user]$ sudo chown -R gitbucket: /home/gitbucket

Create systemd service

To create a new systemd service for GitBucket, open your editor of choice and create a new file:

[user]$ sudo nano /etc/systemd/system/gitbucket.service

and add the following code lines:

Description=GitBucket service

ExecStart=/usr/bin/java -jar /home/gitbucket/gitbucket.war --port=8080 --host=


Start the GitBucket server and set it to start automatically on boot:

[user]$ sudo systemctl enable gitbucket.service
[user]$ sudo systemctl start gitbucket.service

To verify the unit started, run systemctl status gitbucket.service and you should see something like below:

● gitbucket.service - GitBucket service
   Loaded: loaded (/etc/systemd/system/gitbucket.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2016-09-09 18:25:18 CDT; 2s ago
 Main PID: 3578 (java)
   CGroup: /system.slice/gitbucket.service
           └─3578 /usr/bin/java -jar /home/gitbucket/gitbucket.war --port=8080 --host=

Install and configure Nginx

To install the latest stable version of Nginx available on the Ubuntu repositories, run:

[user]$ sudo apt-get -y install nginx

Generate a self signed ssl certificate:

[user]$ sudo mkdir -p /etc/nginx/ssl
[user]$ cd /etc/nginx/ssl
[user]$ sudo openssl genrsa -des3 -passout pass:x -out gitbucket.pass.key 2048
[user]$ sudo openssl rsa -passin pass:x -in gitbucket.pass.key -out gitbucket.key
[user]$ sudo rm gitbucket.pass.key
[user]$ sudo openssl req -new -key gitbucket.key -out gitbucket.csr
[user]$ sudo openssl x509 -req -days 365 -in gitbucket.csr -signkey gitbucket.key -out gitbucket.crt

[user]$ sudo openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
If you don’t want to get warnings associated with self-signed SSL Certificates, you can purchase a trusted SSL certificate here.

Next, create a new Nginx server block:

[user]$ sudo nano /etc/nginx/sites-available/myGitbucket.com
server {
    listen 443 ssl http2;
    server_name myGitbucket.com;

    location / {
        proxy_pass    ;
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout   150;
        proxy_send_timeout      100;
        proxy_read_timeout      100;
        proxy_buffers           4 32k;
        client_max_body_size    500m; # Big number is we can post big commits.
        client_body_buffer_size 128k;

    ssl on;
    ssl_certificate     /etc/nginx/ssl/gitbucket.crt;
    ssl_certificate_key /etc/nginx/ssl/gitbucket.key;
    ssl_dhparam  /etc/nginx/ssl/dhparam.pem;

    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    access_log  /var/log/nginx/mygitbucket.access.log;
    error_log   /var/log/nginx/mygitbucket.error.log;


server {
    listen      80;
    server_name myGitbucket.com;

    add_header Strict-Transport-Security max-age=2592000;
    rewrite ^ https://$server_name$request_uri? permanent;

Activate the server block by creating a symbolic link :

[user]$ sudo ln -s /etc/nginx/sites-available/myGitbucket.com /etc/nginx/sites-enabled/myGitbucket.com

Test the Nginx configuration and restart nginx:

[user]$ sudo nginx -t
[user]$ sudo systemctl start nginx

Open http://myGitbucket.com/ in your favorite web browser and you should see the GitBucket home page. The default username and password are both root.

That’s it. You have successfully installed GitBucket on your Ubuntu 16.04 VPS. For more information about how to manage your GitBucket installation, please refer to the official GitBucket website.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Categories: Tutorials
Tags: ,