Artifactory on Ubuntu 14.04

As part of a new continuous integration (CI) server build I need to install a Maven repository manager or software repository. After much debate I’ve decided to go with Artifactory on Ubuntu but the choice was not easy.

For a while now I’ve been running Nexus but I’ve never been completely happy with it, there’s certainly nothing wrong with it but the interface, in fact the whole system, has always felt clunky even though I was only making light use of it.

The big three repository managers are Archiva, Artifactory and Nexus, there’s a great product comparison here. Looking at the feature matrix there’s not a lot to differentiate between Artifactory and Nexus, both are clearly mature products. Archiva could, I think, do everything I want but it’s just not as feature rich. The thing that really sold me on Artifactory was the ease of integration with Jenkins.

Installing Artifactory on Ubuntu

This guide will cover installing Artifactory on Ubuntu as a service rather than as a standalone process that needs to manually be started.

First check that you have JAVA_HOME correctly configured:

echo $JAVA_HOME

/usr/lib/jvm/java-8-oracle

If your system doesn’t respond with the location of a JVM then you’ll need to set the location. The most likely reason for not having JAVA_HOME set though is because you don’t have a Java package installed. You can either install an OpenJDK package from Ubuntu or, as I have done, install Oracle Java 8 or later as described here.

Now download and unzip Artifactory. I will be installing the system into a folder under /opt as that’s a reasonable choice for a piece of software like this that isn’t part of the regular packaging system and not obviously designed to run under Apache (like for example WordPress or Mantis). You can use wget to download the file but it’ll probably end up with the wrong name due to the use of bit.ly.

cd /opt
unzip artifactory-3.7.0.zip

This will create a directory called artifactory-3.7.0. Now switch to the Artifactory bin directory and run the install script:

cd artifactory-3.7.0/bin/
sudo ./installService.sh

The install script needs to run as root in order to copy files into start up directories etc. The output of that command looks like this:

Installing artifactory as a Unix service that will run as user artifactory
Installing artifactory with home /opt/artifactory-3.7.0
Creating user artifactory...creating... DONE

Checking configuration link and files in /etc/opt/jfrog/artifactory...
Moving configuration dir /opt/artifactory-3.7.0/etc /opt/artifactory-3.7.0/etc.original...creating the link and updating dir... DONE
Creating environment file /etc/opt/jfrog/artifactory/default...creating... DONE
** INFO: Please edit the files in /etc/opt/jfrog/artifactory to set the correct environment
Especially /etc/opt/jfrog/artifactory/default that defines ARTIFACTORY_HOME, JAVA_HOME and JAVA_OPTIONS

Initializing artifactory service with update-rc.d...update-rc.d: warning: default start runlevel arguments (2 3 4 5) do not match artifactory Default-Start values (3 4 5)
 Adding system startup for /etc/init.d/artifactory ...
 /etc/rc0.d/K20artifactory -> ../init.d/artifactory
 /etc/rc1.d/K20artifactory -> ../init.d/artifactory
 /etc/rc6.d/K20artifactory -> ../init.d/artifactory
 /etc/rc2.d/S20artifactory -> ../init.d/artifactory
 /etc/rc3.d/S20artifactory -> ../init.d/artifactory
 /etc/rc4.d/S20artifactory -> ../init.d/artifactory
 /etc/rc5.d/S20artifactory -> ../init.d/artifactory
 DONE

Setting file permissions... DONE

************ SUCCESS ****************
Installation of Artifactory completed

Please check /etc/opt/jfrog/artifactory, /opt/artifactory-3.7.0/tomcat and /opt/artifactory-3.7.0 folders
Please check /etc/init.d/artifactory startup script

you can now check installation by running:
> service artifactory check (or /etc/init.d/artifactory check)

Then activate artifactory with:
> service artifactory start (or /etc/init.d/artifactory start)

More than likely despite having JAVA_HOME correctly set for your account it won’t have been picked up but Artifactory. First run a service check to see what environment variables are being used:

sudo service artifactory check

Checking arguments to Artifactory:
ARTIFACTORY_HOME = /opt/artifactory-3.7.0
ARTIFACTORY_USER = artifactory
TOMCAT_HOME = /opt/artifactory-3.7.0/tomcat
ARTIFACTORY_PID = /opt/artifactory-3.7.0/run/artifactory.pid
JAVA_HOME =
JAVA_OPTIONS = -server -Xms512m -Xmx2g -Xss256k -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+UseG1GC -Djruby.compile.invokedynamic=false -Dfile.encoding=UTF8

It looks like the only one not correctly set is JAVA_HOME which I already know from the check at the start of the article. Now edit the file /etc/opt/jfrog/artifactory/default and update JAVA_HOME.

cd /etc/opt/jfrog/artifactory/
sudo nano default

Add the line:

export JAVA_HOME=/usr/lib/jvm/java-8-oracle

Rerunning the service check sudo service artifactory check should now show the correct JAVA_HOME variable. If you check the Artifactory installation directory and files you’ll notice they are now owned by the new artifactory user. If everything looks good start the service with:

sudo service artifactory start

For some reason on my system the service started cleanly but Tomcat reported that it timed out after waiting 60 seconds. This doesn’t seem to be an issue so just plough on.  You now have Artifactory on Ubuntu and you should be able to access it at http://your_server:8081/artifactory

Proxying Artifactory on Ubuntu

I want to run Artifactory through an Apache server to remove the annoying port number (it’s the little things that matter). In the past I would use either JK or AJP but as I already have the proxy module installed in Apache for another server I’ll be using that instead. Create a new virtual host with a configuration like this:

<VirtualHost *:80>
    DocumentRoot "/var/www/html"
    ServerName artifactory.example.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    ProxyPreserveHost on
    ProxyPass /artifactory http://artifactory.example.com:8081/artifactory
    ProxyPassReverse /artifactory http://artifactory.example.com/artifactory
</VirtualHost>

Assuming that is all working correctly you will be able to access your Artifactory install at “http://artifactory.example.com/artifactory”. It’s worth pointing out that in order for this proxying to work your Apache install must be able to perform a DNS lookup on the domain name used in the proxy configuration e.g. artifactory.example.com.