Instantly Search Your Source Code With OpenGrok

OpenGrok Logo

OpenGrok indexes your source code to allow for instant search over a large codebase which can be an invaluable timesaver. I finished setting this up on a server at work today, here’s how.


OpenGrok requires Tomcat 6 or 7 or Glassfish, in my case I have setup using Tomcat 7 on Ubuntu.

Download & Install

Head over to the OpenGrok website and download the binary package and then unpack this in your chosen installation directory.

Now to deploy the web application simply run the deploy command and restart Tomcat (or whichever container you are using):

You should now be able to see the web interface at http://localhost:8080/source/ assuming you are using Tomcat as I am.

Get Source Code & Index

Although any directory can be used as the source code directory I have chosen to encapsulate this inside my OpenGrok directory:

Now clone / copy in all the code which you would like indexed into this directory via whatever method you feel fit. Once this is done all that is left is to set off indexing, once complete you can search the code using the web interface:


To alter the text shown on the web front-end edit the file /var/lib/tomcat7/webapps/source/index_body.html.

In addition I found that with lots of repos selected for search Tomcat starts to fall over due to the request URL becoming much to large with all the GET variables being included, this generated Tomcat errors of the types:

To resolve this limitation, update the file /var/lib/tomcat7/webapps/source/menu.jspf, line 76 to read:

And also updatethe Container element in /var/lib/tomcat7/conf/server.xml to include the following attribute:

And then restart Tomcat:


If you made a script for updating your source code being indexed, then for extra points you can setup cron to automatically update your source code and index periodically, make a log file for this task (with a better name than the one I chose):

Add the following line in your code updater script to give a complete update / index script:

Open the cron file for your user:

And add the below cronline uses the git downloader listed previously and runs a 2am (you could of course just chain bash commands here with && or ;; rather than using a script as I have):


Done, you should now have a insta-search tool with the index updated on a nightly basis.

Aside: This is not a blog post

About Ingmar Boddington

Codemonkey, Sheffield, UK
This entry was posted in Code, Linux and tagged OpenGrok. Bookmark the permalink.