Wednesday, August 24, 2011

Installing Sonatype Nexus on a Linux server

Recently I had to setup Nexus on my Ubuntu machine. The process is quite straightforward, but I'll try to describe every step as if using a Linux server (without GUI, only shell commands): this could scare the basic Linux user, but trust me, it isn't difficult.
Let's get started.
  1. Download nexus with wget and place in a folder of your choice. Let's assume we are installing Nexus on /usr/local/nexus and unpack it in the same folder
    cd /usr/local
    sudo mkdir nexus
    sudo wget
    sudo tar -xvzf nexus-oss-webapp-1.9.2-bundle.tar.gz
    I'm assuming you have a JAVA_HOME var configured and that this is attached to the PATH variable (ie: you hava Java installed and running. If you want to know how to install Java, I've wrote a simple step-by-step guide
  2. Set up some variable (using the global profile).
    sudo gedit /etc/profile
    and add these lines
    export NEXUS_PLATFORM=linux-x86-32 # specify your platform here
    export NEXUS_HOME=/usr/local/nexus/nexus-oss-webapp-1.9.2
  3. Now we have nexus downloaded and installed. This will not suffice because the Nexus won't start as a service. To accomplish this task we need to do something more. First, we need to modify the file that launches Nexus
    sudo gedit $NEXUS_EXEC/nexus
    and modify these lines
    # Application
    APP_LONG_NAME="Sonatype Nexus OSS"
    # Wrapper
    # Priority at which to run the wrapper.  See "man nice" for valid priorities.
    #  nice is only used if a priority is specified.
    # Location of the pid file.
  4. Now you have to set up Nexus as a service. There are two ways to do so:
    • copy the nexus launcher in /etc/init.d, make it executable and update system services
      sudo cp $NEXUS_EXEC/nexus /etc/init.d/nexus
      sudo chmod 755 /etc/init.d/nexus
      sudo update-rc.d nexus defaults
    • create a launcher, make it executable and update system services
      sudo gedit /etc/init.d/nexus # file does not exist, will be created
      add the lines
      COMMAND_LINE="/usr/local/nexus/nexus-oss-webapp-1.9.2/bin/jsw/linux-x86-32/nexus start"
      eval $COMMAND_LINE
      sudo chmod 755 /etc/init.d/nexus
      sudo update-rc.d nexus defaults
You are done! Restart your system and start working with your new Nexus repository. Note that if you want to import and old repository, you just need to overwrite the /usr/local/nexus/sonatype-work folder

No comments:

Post a Comment