How to Install Nexus on Ubuntu 16.04

If you manage more than one JAVA module – you’ll need Nexus. Nexus works best alongside

  1. JAVA (.jar, .ear, .war) or Groovy or Scala software
  2. a Jenkins Continuous Integration Server (or Continuum or Hudson)
  3. a Maven or ANT or SBT or Gradle build management tool

Before installing your Nexus repository – come see ours, in the flesh.

see our Nexus Repository – in the flesh

Why not see what it looks like in the flesh.

Nexus or Artifactory or Archiva

Nexus integrates best with various continuous integration, test and deploy services.

Unlike Artifactory and Archiva – it stores your build output on the filesystem which makes migration, replication and backup easier than the rest. The database storage employed by Archiva (Apache Derby) and Artifactory (Java Content Storage or MySQL) creates a steeper learning curve.

How to Install Nexus on Ubuntu 16.04

To install Nexus on Ubuntu 16.04 is easier due to dedicated handling of JAVA (and usually Tomcat) based Middleware. For best results stick to the directory locations given here.

  1. Use Oracle Java8 – see (How to Install Oracle Java on Ubuntu 16.04)
  2. Use the Ubuntu 16.04 Nexus distribution or use the Nexus Download Page
  3. Go to your home directory
  4. Pull wget
  5. Unpack Nexus using tar -xvzf nexus-repository-v3.tar.gz
  6. Remember the top level directory name (eg nexus-3.0.1-01)
  7. Change directory to opt with cd /opt
  8. Use sudo to create nexus folder sudo mkdir nexus
  9. Jump into the nexus folder cd nexus
  10. Copy using sudo cp -R ~/nexus-3.0.1-01/* .
  11. Visit the nexus configuration file /opt/nexus/bin/nexus aptly named nexus.
  12. Add “nexus” to this line run_as_user='nexus'
  13. Add this setting NEXUS_HOME="/opt/nexus"
  14. Update the nexus configuration file » sudo cp <<nexus-config-file>> /opt/nexus/bin/nexus
  15. Make the nexus configuration executable sudo chmod a+x /opt/nexus/bin/nexus
  16. Give our new nexus user ownership » sudo chown -R nexus:nexus /opt/nexus
  17. Assume the position of nexus user » su - nexus
  18. Type in whoami to check who you are.
  19. To startup nexus we go to its bin folder cd /opt/nexus/bin
  20. It is time to fire up nexus ./nexus start
  21. The response Starting nexus is not the most verbose!

If you verify using wget http://localhost:8081/nexus you can expect a 200 response code. This check circumvents external connectivity issues that often plague remote middleware service installs.

Peek at our Nexus Configuration File

You can peek at our nexus configuration file by checking it out of our Subversion SCM asset base. If you like it you can navigate to it and copy it directly into place with the commands below.

» svn checkout configure-mirror
» sudo cp /opt/nexus/bin/nexus

Now let’s visit the Nexus repository manager.

The Build Business Websites Nexus Repository Manager

Look at our Nexus Repository Manager page (to see what it looks like).

The default URL for Nexus is http://your-server-hostname:8081/nexus assuming you did not change the default 8081 port number in the /opt/nexus/bin/nexus configuration file.

@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@
@@@ Introduction to Installing Nexus in Ubuntu 16.04 and 14.04 @@@
@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@

Don’t use archiva – the software is half-baked and has a multitude of bugs.
Creating the admin user is time consuming – the repositories on disk created nested loops
Configuration needs hacking.

Beware of artifactory – it pretends to be free but after a couple of months they sting you with a loophole in the licensing! To understand more read here.
So Nexus OSS is the only fully featured stable repository manager. But be careful.

~~ Nexus Bites !! Do NOT install it without running through the Bites and Bruises.

– Do NOT download Nexus 3 – All documentation refers to Nexus 2. Final version is 2.13.
– Use Oracle Java
– Create OS user
– Check the full list of !gotchas!

Create nexus Operating System User

It is important to create a user who will (amongst other things) execute (start and stop) the nexus application. Running nexus as root is much more trouble than it is worth.

We regret using this command to create the user because the home directory is / and it suffers permission problems and has unwanted side effects like an inability to work inside emacs (which needs emacs.d).

sudo adduser --no-create-home --disabled-login --disabled-password nexus

Adding user `nexus' ...
Adding new group `nexus' (1002) ...
Adding new user `nexus' (1002) with group `nexus' ...
Not creating home directory `/home/nexus'.
Changing the user information for nexus

We (retrospectively) regret commissioning a password for the nexus user with sudo passwd nexus

For the next nexus install we will use sudo adduser nexus
If all goes well we will delete the above advice. The advice is included above because despite our regret – we cannot (yet) guarantee that a user created in the standard manner will work.

Unravel the Twin Nexus Archives

We used the /tmp location to unpack the Nexus archive. We then copied the twin directories into the /var/lib base in keeping with Ubuntu tradition.

Ubuntu Tradition - Which Install Directory?

Ubuntu tradition is to install packages into /var/lib. This is where aptitude installs Jenkins, MediaWiki and parts of MySQL. Linux tradition dictates one folder for installation and another for data and configuration. This strategic divide creates a simpler upgrade process.

Let’s visit the commands that unpack nexus and copy the twin folders into place.

Unpack the Nexus Archive

We make use of the temporary directory – and we do not forget to clean up after ourselves.

  1. cd /tmp
  2. mkdir nexus-unpack
  3. cd nexus-unpack
  4. cp /home/ubuntu/nexus-213-bundle.tar.gz .
  5. tar -xzvf nexus-213-bundle.tar.gz

After unpacking – we copy our Nexus artifacts into two locations.

Deploying nexus and sonatype-work directories

sudo cp -R nexus-2.13.0-01/* /var/lib/nexus
sudo cp -R sonatype-work /var/lib

Tidy Up After Ourselves

The Nexus archive is 70 MB! This is significant when deploying to miserly Amazon AWS (or Google) cloud servers that loan out barely a handful of gigabytes.

@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@ Clean the Temp Folder and Home Dir
@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

cd /tmp
rm -r nexus-unpack
cd $HOME
rm nexus-213-bundle.tar.gz

@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@ Give ownership of both to nexus
@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

cd /var/lib
sudo chown -R nexus:nexus sonatype-work
sudo chown -R nexus:nexus nexus

@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Grab a putty shell.

su – nexus

cd /var/lib/nexus
./bin/nexus console

After all is said and done do the logs spitted out end like this?
Do the last couple of lines look like the below.

jvm 1    | 2016-08-02 01:19:39,261+0100 INFO  [jetty-main-1] *SYSTEM - Discovere\
d 1971 resources
jvm 1    | 2016-08-02 01:19:39,262+0100 INFO  [jetty-main-1] *SYSTEM - Max-age: 30 d\
ays (2592000 seconds)
jvm 1    | 2016-08-02 01:19:39,334+0100 INFO  [jetty-main-1] *SYSTEM - Met\
rics enabled
jvm 1    | 2016-08-02 01:19:39,375+0100 INFO  [jetty-main-1] *SYSTEM org.eclipse.jetty.server.AbstractConnector - Started InstrumentedSelectChan\
jvm 1    | 2016-08-02 01:19:39,376+0100 INFO  [WrapperListener_start_runner] *SYSTEM - Started
jvm 1    | 2016-08-02 01:19:39,378+0100 INFO  [jetty-main-1] *SYSTEM - Running

@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@ Test the Url
@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

cd /tmp
wget http://localhost:8081/nexus

–2016-08-02 01:39:56– http://localhost:8081/nexus
Resolving localhost (localhost)…
Connecting to localhost (localhost)||:8081… connected.
HTTP request sent, awaiting response… 302 Found
Location: http://localhost:8081/nexus/ [following]
–2016-08-02 01:39:56– http://localhost:8081/nexus/
Reusing existing connection to localhost:8081.
HTTP request sent, awaiting response… 200 OK
Length: 8026 (7.8K) [text/html]

2016-08-02 01:39:56 (847 MB/s) – ‘nexus’ saved [8026/8026]

@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@ Configure the Apache Proxying
@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

The [] configuration ( already @ middleware/nexus/ )

Change the [@@@@@@@ application host and the@@@@@@@@] web application context path

NO NO NO #################### FROM =] application-host=
NO NO NO #################### [TO] =]

FROM =] nexus-webapp-context-path=/nexus
[TO] =] nexus-webapp-context-path=/library

@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@ Bounce Nexus and Apache Web Server
@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Stop Apache ==] sudo service apache2 stop
Stop Nexus ==] ./bin/nexus stop ( or Ctrl-C if running console )
Start Nexus ==] ./bin/nexus console
Start Apache ==] sudo service apache2 start

@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@ Setting the Base Url
@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


When setting the base URL
1 – do not use Force button – do no check the box
2 – leave the default Http Proxy (and Https Proxy) settings off – (unchecked)
3 – Do not add the context path to the Base Url ==>


#3 is in contrast to other configurations (like Jira) where the Application Url includes the
main bit and the slash (service) context. With Nexus – it wants to be clever enough to add that context
path string onto the base Url specified – so we leave him to it.

@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@ Get Nexus to run as a Service
@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Optional as [bbw] is not bounced very often

You can do this from command line with
./bin/nexus start

But to get nexus to startup on reboot and also
respond to sudo service nexus restart (+more)
commands we must configure it to run as a service.

(See documentation)

My Nexus Is Running

Pat yourself on the back if you have managed to install the repository manager.

In order to achieve the ideals of DevOps, nightly builds, feedback, fail fast, continuous delivery, continuous integration, supply chain automation, daily or even twice daily releases – requires that you have a repository manager under your control.

Middleware Services - Easy vs Best of Breed

Installing the best of breed is not synonymous with riding a crest or breeze. Nexus is the best of breed - however give yourself a couple of days to get a feel for things - it's worth it.

Well done – Nexus is installed – and we believe that your productivity (and/or that of your team) – will come on in leaps and bounds. So it’s lights out and away you go.

Leave a Reply

Your email address will not be published. Required fields are marked *