This guide is for installing Sourcegraph on Ubuntu 18.04 / Ubuntu 16.04 LTS. Sourcegraph is a fast, open-source, fully-featured code search and navigation engine.

Features of Sourcegraph

Sourcegraph has the following features:

Install Sourcegraph code search tool on Ubuntu 18.04 / Ubuntu 16.04 LTS

There are two ways to run Sourcegraph on Ubuntu 18.04 & Ubuntu 16.04 LTS.

  1. Running Sourcegraph in Docker
  2. Installing Sourcegraph on your local system

The method we’ll use in this guide is running Sourcegraph in Docker, which is the easiest and recommended.

Step 1: Install Docker Engine

You need Docker Engine installed and running on your system, use our Docker installation guide How to install Docker CE on Ubuntu / Debian / Fedora / Arch / CentOS

You can check the installed version of Docker using the command:

# docker version
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:24:51 2018
 OS/Arch:           linux/amd64
 Experimental:      false

  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:23:15 2018
  OS/Arch:          linux/amd64
  Experimental:     false

Step 2: Start Sourcegraph container

Once Docker is running, you can start Sourcegraph  container by executing commands below on your terminal  ( Not recommended method; use systemd)

docker run --publish 7080:7080 --rm \
--volume ~/.sourcegraph/config:/etc/sourcegraph \
--volume ~/.sourcegraph/data:/var/opt/sourcegraph \
--volume /var/run/docker.sock:/var/run/docker.sock \

Manage Sourcegraph with Systemd ( recommended)

It is possible to manage sourcegraph docker container with systemd. Create a service unit file under /etc/systemd/system/sourcegraph.service

Add the following contents:

Description=Sourcegraph code search and navigation engine

ExecStartPre=-/usr/bin/docker kill sourcegraph
ExecStartPre=-/usr/bin/docker rm sourcegraph

ExecStart=/usr/bin/docker run \
--name sourcegraph \
-p 7080:7080 \
-v /var/sourcegraph/config:/etc/sourcegraph \
-v /var/sourcegraph/data:/var/opt/sourcegraph \
-v /var/run/docker.sock:/var/run/docker.sock  \

ExecStop=-/usr/bin/docker kill sourcegraph
ExecStop=-/usr/bin/docker rm sourcegraph

Docker options used:

  • --name sourcegraph: Name of the container
  •  -p 7080:7080 : Map port 7080 on the host to port 7080 on the container
  • -v /var/sourcegraph/config:/etc/sourcegraph: Volume mapping for storing Sourcegraph configurations files
  • -v /var/sourcegraph/data:/etc/sourcegraph: Volume mapping for storing Sourcegraph data – PostgreSQL, redis and repository data.

When Sourcegraph is ready, access the web interface by visiting.http://serverip:7080

On first access, you’ll be prompted to create an admin account.

sourcegraph create admin account min

Step 3: Add Repositories

As an example, we’ll add Github repository to Sourcegraph. For this, you need to create a new Access Token from .

github create new token min

Give the token a name and access privileges. The repo scope should be enough for Sourcegraph to access and clone the repositories on your Github account.

Make sure to copy your new personal access token after creation since you won’t be able to see it again!.

Once you have the Github token ID, Login to Sourcegraph Dashboard and navigate to Admin > Configuration > Add repositories. Add your token ID under the token quotes section and save the changes.

sourcegraph add github access token min


"token": "9bc5a980e443373b9ffd5e46e7dce3cbe863021b"

After a short while, your Github repositories should appear under the Repositories section but disabled.

sourcegraph repositories min

Enable these repositories to start searching on them.

sourcegraph enable repositories min

You can learn more on how to Add Repositories to Sourcegraph. Refer the Official Documentation for other Configurations and tweaks.

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here