How to setup Opengrok ( source code search and cross reference engine ) on Ubuntu

OpenGrok is a fast and usable source code search and cross reference engine. It helps you search, cross-reference and navigate your source tree. It understands various program file formats and history from many Source Code Management systems. In other words it lets you grok (profoundly understand) source code and is developed in the open, hence the name OpenGrok. It is written in Java.

Following steps helps you to setup opengrok on ubuntu machines.

Dependancies – Opengrok is dependent on JDK and universal ctags which can be installed as,

$ sudo apt-get install openjdk-8-jdk
$ sudo apt-get remove exuberant-ctags
$ sudo snap install universal-ctags

You can refer to “How to install universal-ctags on Ubuntu” to understand more about universal ctags.

You will also needs to install Tomcat as mentioned below,

$ mkdir devlab
$ cd devlab
$ wget -c

$ tar xvf apache-tomcat-8.5.53.tar.gz
$ mv apache-tomcat-8.5.53 tomcat

You can also directly download tomcat 8 from and extract as you want.

Next, we need to create some dependent directories and copy source.war from opengrok to tomcat as,

$ mkdir -p $PWD/opengrok/{src,data,dist,etc,log}
$ tar -C $PWD/opengrok/dist --strip-components=1 -xzf opengrok-1.3.11.tar.gz

$ cp $PWD/opengrok/dist/doc/ $PWD/opengrok/etc
$ cp $PWD/opengrok/dist/lib/source.war tomcat/webapps/

Now, we will write simple script to source the environment variables as required to setup tomcat and opengrok as,

$ vim

Now, we can start the tomcat server as,

#start tomcat server, 
$ bash $PWD/tomcat/bin/
# server will be started at http://localhost:8080/

as we can see in script, we have set OPENGROK_INSTANCE_BASE as $PWD/opengrok/src/ i.e. opengrok/src directory from current “devlab” directory. This opengrok/src/ direvtory is where we have to download the source for which we want to build the cross reference / search database.

For example, we used following two git sources, you can use any git from your source code,

$ cd $PWD/opengrok/src
$ git clone
$ git clone

Now, the last step to get everything working is to run the indexer which will create the indexing of the source which can be used for searching using browser..

$ cd devlab 
$ vim 
#check where ctags is using "which ctags" command...
java \
    -Djava.util.logging.config.file=$PWD/opengrok/etc/ \
    -jar $PWD/opengrok/dist/lib/opengrok.jar \
    -c /snap/bin/ctags \
    -s $PWD/opengrok/src -d $PWD/opengrok/data -H -P -S -G \
    -W $PWD/opengrok/etc/configuration.xml -U http://localhost:8080/source

Time required for indexing will be depending on size of your source code from $PWD/opengrok/src , once indexing is complete you will see the opengrok up and running at http://localhost:8080/source/ as shown below,


You can download the entire source code from

References –

Leave a Comment