Installing Nexus Repository 3 on Ubuntu Server with Secure Remote Access
This tutorial covers everything from Java preparation to automation as a service and secure access from an external PC
Nexus 3 requires Java 8 specifically to function correctly
Nexus 3 was built on an architecture that relies on version 8-specific libraries
Let’s confirm the exact path for Java 8:
update-java-alternatives -l
That will list all the versions of Java you have installed
java 8 instalation:
sudo apt update && sudo apt install openjdk-8-jdk
verification:
java -version
It should say 1.8.x (the current version)
java 8 & nexus (This is if you already have Nexus installed and the .service command from systemctl to set Java version 8 is not working)
As an added measure, you can also edit the Nexus options file to “pin” the version:
Nexus has a specific file for this. Let’s edit it:
sudo vi /opt/nexus/bin/nexus.vmoptions
At the beginning of the file (or by searching for the line INSTALL4J_JAVA_HOME_OVERRIDE), make sure it points to your Java 8. If the line is missing, you can add it at the top:
-Djava.home=/usr/lib/jvm/java-1.8.0-openjdk-amd64
Once the service is running, you can confirm which version of Java the Nexus process is using with this command:
ps -ef | grep nexus
In the output of that command, you’ll see a very long line that starts with the path to the Java executable. If you configured everything correctly, you should see something like this:
… /usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java -Dinstall4j.jvmDir=…
Nexus Installation
Download the official Sonatype package
Unzip to /opt/
You will have two folders:
- /opt/nexus (the program)
- and /opt/sonatype-work (your data and repositories)
For security reasons, do not run it as root
Configured as a Service (Systemd)
so that Nexus starts automatically when the server is turned on and runs in the background
sudo vi /etc/systemd/system/nexus.service
content:
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=axeldamian
Restart=on-abort
[Install]
WantedBy=multi-user.target
*axeldamian is a linux ubuntu server user
Add the line Environment within the [Service] section:
[Service]
Type=forking
LimitNOFILE=65536
Environment="JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64"
ExecStart=/opt/nexus/bin/nexus start
...
The key is the JAVA_HOME environment variable within the service file, You are giving a direct instruction to the process
The system ignores global Java: Even if the java -version command in your terminal says “21”, the Nexus service will read that line and look for the executable only in the Java 8 path you specified.
So, modifying /opt/nexus/bin/nexus.vmoptions is one alternative, but you actually need to modify /etc/systemd/system/nexus.service [Service] environment=
There are two layers of security to ensure nothing goes wrong.
- /etc/systemd/system/nexus.service (The main one): By putting Environment=”JAVA_HOME=…” within the [Service] section, you are telling the operating system: “When you launch this process, prepare this environment with Java 8.” This is the cleanest and standard way in Linux
- /opt/nexus/bin/nexus.vmoptions (The Booster): Modifying this file is an alternative (or add-on) that directly tells the Nexus binary which Java to use, ignoring any other system settings
Ideally, you should do it in the .service file, because you centralize the service administration there
activation commands
so that Linux knows that this service should start automatically:
Reload the service list:
sudo systemctl daemon-reload
Enable automatic startup when the server boots:
sudo systemctl enable nexus
sudo systemctl enable nexus
Start the service right now:
sudo systemctl start nexus
Check if it’s turned on:
sudo systemctl status nexus
Check if the status appears as active (running)
Turn it off:
sudo systemctl stop nexus
Restart it:
sudo systemctl restart nexus
View real-time logs:
journalctl -u nexus -f