Installing Nexus on Ubuntu 11.10 and Tomcat 6 Part 1

Posted by: TomS on April 10, 2012 @ 7:37 am

I’ve used Maven and Nexus at work quite extensively, and since I’ve become familiar with the tooling, I’ll never go back.  When using a mature language like Java that has an expansive ecosystem, dependency management is a must.  Maven has its rough edges, but it does get the job done, and I’ve always been pleasantly surprised with how easy it is to use Nexus and how little maintenance it really requires.

I’m planning on doing a bit more Java development at home, and I’d like to have my own Nexus repository hosted on my internal network.  Part 2 of this article will cover configuring Nexus and the benefits of using it.  In this part of the article, I’ll walk through the steps for setting up and configuring Nexus from a base Ubuntu 11.10 Server installation.

For my purposes, I would like the end result of my installation to be that I can go to (a DNS name on my internal network) and be able to interact with Nexus, so I’ll be doing some additional configuration with Apache Web Server to make this happen.

Installing Tomcat

Nexus comes packaged as a war, and you’ll need to run it in a Java application server or servlet container.  For my home use, Tomcat fits the bill, and Tomcat 6 is nicely integrated into Ubuntu, so that will be my servlet container of choice.

Installation of Tomcat in Ubuntu is pretty straight forward.  I’ve paraphrased the steps from Ubuntu’s documentation.

You can install tomcat directly with apt-get.

sudo apt-get install tomcat6

After installing tomcat, you can start and stop it using the init.d script.  Its a good idea to start it up at this point and make sure it works.  Just run the command below and then point your browser to localhost:8080.  You should see the Tomcat “It Works!” page.

sudo /etc/init.d/tomcat6 start

If all went smoothly, you can stop tomcat with the following command.

sudo /etc/init.d/tomcat6 stop

The following steps will install the tomcat documentation, administration, and examples servlets.  These are not required, but if you’re going to be messing around with Tomcat these can be quite handy.  If you’re going to be exposing your Tomcat instance publicly, however, I’d recommend skipping these steps.

sudo apt-get install tomcat6-docs
sudo apt-get install tomcat6-admin
sudo apt-get install tomcat6-examples

You’ll also want to modify your tomcat-users configuration by editing /etc/tomcat6/tomcat-users.xml.  Add the following lines below.  This will create the required roles for the admin app and assign it to the admin user identified by the password you include in your file.

<role rolename="admin"/>
<role rolename="manager"/>
<user username="admin" password="mysecretpass" roles="admin,manager"/>

Finally, since I’m always going to want Nexus to be available, I’d like to launch Tomcat when my Ubuntu server launches.  Ubuntu should do this by default, but you can toggle Tomcat launching at startup by using the update-rc.d script.

# remove tomcat6 from server startup
sudo update-rc.d tomcat6 remove
# add tomcat6 to server startup
sudo update-rc.d tomcat6 defaults

Installing Nexus

First of all, you’ll need to create a work directory for Nexus.  This is the directory where Nexus will store all its binary files.  By default, this directory is sonatype-work in /usr/share/tomcat6.  After creating the directory, you’ll also want to change the ownership to the tomcat6 user.

sudo mkdir /usr/share/tomcat6/sonatype-work
sudo chown tomcat6:tomcat6 /usr/share/tomcat6/sonatype-work

You can download the latest Nexus distribution from Sonatype’s download page.  You’ll want to just get the WAR distribution.  As of writing this article, 2.0.3 is the latest distribution, and the one I’ve chosen to use.

With the Ubuntu packaged Tomcat, your default location for webapps is /var/lib/tomcat6/webapp, so you’ll want to download the nexus war and copy it to this directory.

sudo wget
sudo cp nexus-2.0.3.war /var/lib/tomcat6/webapps/nexus.war

You now should be able to go to localhost:8080/nexus and see the Nexus home screen.  Additionally, you should be able to log in to the application with the default username/password admin/admin123.  I recommend changing this immediately.

Proxying Nexus Through Apache

I want to access Nexus not at localhost:8080/nexus, but rather where my.home is the domain I use for my local network.  The server that currently is hosting Tomcat in my case is currently called, and I already have this properly configured on my local DNS.  I am now going to create an alias for called

To do this, I modify /etc/bind/zones/my.home.db and add the following line.

nexus         IN      CNAME   server

and then I restart bind.

sudo /etc/init.d/bind9 restart

To check if my DNS name took hold correctly, I simply accessed my Tomcat instance over the DNS name and not localhost.  So try to navigate to

This brought me again to the Nexus home screen, so this was all configured correctly.

The next few steps involve a few moving pieces.  Essentially, incoming requests will come in through the Apache Web Server.  The Web Server will use the Apache Tomcat connector to forward the request over to Tomcat and have the request served.

Apache Tomcat connector, more commonly called mod_jk available, allows you to easily proxy Tomcat applications through Apache.  It needs to be installed separately from Apache in Ubuntu.  The following steps will install and enable it.

sudo apt-get install libapache2-mod-jk
sudo a2enmod jk
sudo /etc/init.d/apache2 restart

With mod_jk enabled, I can now create a site for Nexus with the mod_jk connector enabled.  Create a Virtual Host configuration for you site that uses JkMount to “mount” all Tomcat contexts to an Apache path.  This file shold go in /etc/apache2/sites-available/nexus

Mine looks like this.

<VirtualHost *>

   <IfModule mod_jk.c>
      JkMount /* nexus_worker

   ErrorLog /var/log/apache2/error.log
   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel warn
   CustomLog /var/log/apache2/access.log combined


To enable this site, run the following command.  It will properly symlink your new site configuration into the list of enabled sites for Apache.

sudo a2ensite nexus

The Apache Tomcat Connector uses a configuration file.  Configuration can allow you to proxy to multiple Tomcat instances and load balance between them amongst several other features.  For my purposes, I’m going to just setup a new worker that will point to a specific VirtualHost in Tomcat.  The Ubuntu installation puts the system wide configuration file at /etc/libapache2-mod-jk/  I added the following lines to create a new ajp13 connector to the Virtual Host.

#add nexus_worker to the list of active workers (ajp13_worker already was defined)

#define the new nexus_worker

The final bit of configuration is to update Tomcat.  This requires updating the server.xml located at /etc/tomcat6/server.xml.

I uncommented the definition of the AJP 1.3 connector in the <Server> configuration (note how the port matches the worker configuration above)

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Finally, within Engine, I added a second host.  This host will capture all requests that come into Tomcat via the domain name.  Tomcat will serve up apps from the directory specified by “appBase” and I additionally noted that the nexus.war file should actually be deployed as the root context.

<Host name="" appBase="nexus"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
   <Context docBase="nexus.war" path=""/>

Now that the new host is added, we’ll need to create the directory for the new host and move Nexus there.

sudo mkdir /var/lib/tomcat6/nexus
sudo chown tomcat6:tomcat6 /var/lib/tomcat6/nexus
sudo mv /var/lib/tomcat6/webapps/nexus.war /var/lib/tomcat6/nexus/nexus.war
sudo rm -rf /var/lib/tomcat6/webapps/nexus*

Everything should be set up now.  Simply restart Tomcat (will take a minute or so for Nexus to fully start up, so wait a bit) and Apache and you should be able to get to Nexus now at

Also note that only the applications deployed to the nexus context are proxied.  If you try to access the Tomcat manager apps, they will not be available through, but they are still available via localhost:8080.

Nexus Up and Running

Nexus Up and Running


So that’s it.  Shortly, I’ll have a follow up post on what to do with Nexus now that its installed.

Part 2 of this article is now available.

One response to “Installing Nexus on Ubuntu 11.10 and Tomcat 6 Part 1”

  1. […] Part 1 of this post, I covered performing a basic installation of Nexus in a Tomcat servlet container on […]

Leave a Reply