I am trying to install Sonatype Nexus 3 as a service via system.d and it fails due to INSTALL4J_JAVA_HOME not being set (or at least, so claims systemctl). I use SDKMan! (http://sdkman.io) to manage my Java installation. I am following the Sonatype directions at https://help.sonatype.com/repomanager3/installation/run-as-a-service .
I can run it as the user specified in run_as_user in a bash shell with no difficulties.
How do I make the java home environment variable provided by SDKman visible to system.d?
TL:DR; to resolve, add an
Environmentsection to the system.d service file:Long-form answer:
As of this writing, the Sonatype documents say to use the following file as your
/etc/systemd/system/nexus.servicefile, which works great if you installed java to your service user via the system distribution (ensuring your distro's java home is managed by the system). That doesn't work to resolve my question:To resolve, you must add the Environment variable to the system.d service file (with
your_userreplaced by the user you are runningnexusas, and/opt/nexusbeing replaced by your nexus install location):