I'd like to know how to install Sonatype Nexus 2 as a service on GNU/Linux in order to get it configured properly and started automatically at startup.
2 Answers
Create a nexus user with sufficient access rights to run the service
useradd nexus
Copy $NEXUS_HOME/bin/nexus to /etc/init.d/nexus Make the /etc/init.d/nexus script executable and owned by the root user:
chmod 755 /etc/init.d/nexus
chown root /etc/init.d/nexus
Edit this script changing the following variables:
- Change NEXUS_HOME to the absolute folder location (e.g., NEXUS_HOME="/usr/local/nexus")
- Set the RUN_AS_USER to nexus or any other user with restricted rights that you want to use to run the service. You should not be running the repository manager as root.
- Change PIDDIR to a directory where this user has read/write permissions (e.g, PIDDIR="/home/nexus/"). Create it if it does not exist.
-Change the owner and group of the directories used by the repository manager, including nexus-work configured in nexus.properties defaulting to sonatype-work/nexus, to the nexus user that will run the application.
chown nexus:nexus NEXUS_HOME -R
-If Java is not on the default path for the user running the repository manager, add a JAVA_HOME variable which points to your local Java installation and add a $JAVA_HOME/bin to the PATH.
Run as a Service on Red Hat, Fedora, and CentOS
This script has the appropriate chkconfig directives, so all you need to do is to add the repository manager as a service is run the following commands:
cd /etc/init.d
chkconfig --add nexus
chkconfig --levels 345 nexus on
service nexus start
Starting Nexus Repository Manager Pro...
tail -f NEXUS_HOME/logs/wrapper.log
The second command adds nexus as a service to be started and stopped with the service command. chkconfig manages the symbolic links in /etc/rc[0-6].d which control the services to be started and stopped when the operating system restarts or transitions between run-levels. The third command adds nexus to run-levels 3, 4, and 5. The service command starts the repository manager, and the last command tails the wrapper.log to verify that it has been started successfully. If the repository manager has started successfully, you should see a message notifying you that it is listening for HTTP.
Runs as a Service on Ubuntu and Debian
The process for setting up the repository manager as a service on Ubuntu differs slightly from the process used on a Red Hat variant. Instead of running chkconfig, you should run the following sequence of commands once you’ve configured the startup script in /etc/init.d.
cd /etc/init.d
update-rc.d nexus defaults
service nexus start
Starting Nexus Repository Manager Pro...
tail -f NEXUS_HOME/logs/wrapper.log

- 3,552
- 3
- 26
- 25
For Nexus 2 documentation is at
https://books.sonatype.com/nexus-book/reference/install-sect-service.html
for Nexus 3 it is at
https://books.sonatype.com/nexus-book/reference3/install.html#service-linux
The recommendations differ. One example is instead of copying nexus
start script, use sym link
sudo ln -s $NEXUS_HOME/bin/nexus /etc/init.d/nexus

- 60,022
- 51
- 208
- 332