{"id":10790,"date":"2021-10-21T21:02:16","date_gmt":"2021-10-21T18:02:16","guid":{"rendered":"https:\/\/kifarunix.com\/?p=10790"},"modified":"2024-03-18T13:28:21","modified_gmt":"2024-03-18T10:28:21","slug":"install-nexus-repository-manager-on-debian-11","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-nexus-repository-manager-on-debian-11\/","title":{"rendered":"Install Nexus Repository Manager on Debian 11"},"content":{"rendered":"\n
This tutorial describes how to install Nexus repository manager on Debian 11.<\/p>\n\n\n\n
Nexus is the World\u2019s #1 repository manager for build artifacts. There exist two versions of Nexus repository manager;<\/p>\n\n\n\n
In this tutorial, we will be installing the OSS version.<\/p>\n\n\n\n
Ensure that the minimum requirements are met by your system before you can proceed, as outlined on Nexus system requirements page, links provided below.<\/p>\n\n\n\n
Update system package cache;<\/p>\n\n\n\n
apt update<\/code><\/pre>\n\n\n\nInstall Java on Debian 11<\/h3>\n\n\n\n
Nexus repository manager requires Java 8 Runtime Environment (JRE).<\/p>\n\n\n\n
Debian 11 repos do not provide Java 8 packages. Hence, we opted to use repos for Debian 9 to install Java 8.<\/p>\n\n\n\n
cat > \/etc\/apt\/sources.list.d\/java-8.list << 'EOL'\ndeb http:\/\/ftp.debian.org\/debian stretch main\ndeb-src http:\/\/ftp.debian.org\/debian stretch main\nEOL<\/code><\/pre>\n\n\n\napt update<\/code><\/pre>\n\n\n\nYou can simply run the command below to install Java 8 on Debian 11;<\/p>\n\n\n\n
apt install openjdk-8-jdk<\/code><\/pre>\n\n\n\nConfirm the installed version of Java;<\/p>\n\n\n\n
java -version<\/code><\/pre>\n\n\n\nRemove Debian 9 repos;<\/p>\n\n\n\n
rm -rf \/etc\/apt\/sources.list.d\/java-8.list<\/code><\/pre>\n\n\n\nCreate Dedicated Nexus System Account<\/h3>\n\n\n\n
As a security precaution, Nexus Repository Manager should NOT be run as the root<\/strong><\/code> user. Instead, create a system account for Nexus;<\/p>\n\n\n\nuseradd -M -d \/opt\/nexus -s \/bin\/bash -r nexus<\/code><\/pre>\n\n\n\nAllow the nexus<\/strong><\/code> user to run all commands with sudo without password.<\/p>\n\n\n\napt install sudo -y<\/code><\/pre>\n\n\n\necho \"nexus ALL=(ALL) NOPASSWD: ALL\" > \/etc\/sudoers.d\/nexus<\/code><\/pre>\n\n\n\nDownload Nexus Repository OSS Tarball<\/h3>\n\n\n\n
Navigate to Nexus repository OSS downloads page<\/a>, register for an account and download Nexus repository OSS for Unix tarball.<\/p>\n\n\n\nYou can simply obtain the link and pull the tarball using wget command as shown below. Note that this downloads the current stable release version of Nexus, 3.35.0-02<\/strong><\/code>, as of this writing. Be sure to get the link to the latest version from downloads page.<\/p>\n\n\n\nwget https:\/\/sonatype-download.global.ssl.fastly.net\/repository\/downloads-prod-group\/3\/nexus-3.35.0-02-unix.tar.gz<\/code><\/pre>\n\n\n\nInstalling Nexus Repository Manager on Debian 11<\/h3>\n\n\n\nExtract the tarball<\/h4>\n\n\n\n
Extact Nexus to the nexus<\/strong><\/code> user home directory, which in this guide is \/opt\/nexus<\/strong><\/code>.<\/p>\n\n\n\nmkdir \/opt\/nexus<\/code><\/pre>\n\n\n\ntar xzf nexus-3.35.0-02-unix.tar.gz -C \/opt\/nexus --strip-components=1<\/code><\/pre>\n\n\n\nChecking the contents of the \/opt\/nexus directory;<\/p>\n\n\n\n
ls \/opt\/nexus\/*<\/code><\/pre>\n\n\n\n\nbin\ndeploy\netc\nlib\nnexus3\nNOTICE.txt\nOSS-LICENSE.txt\nPRO-LICENSE.txt\npublic\nreplicator\nsystem\n<\/code><\/pre>\n\n\n\nSet the proper ownership of the nexus directory;<\/p>\n\n\n\n
chown -R nexus: \/opt\/nexus<\/code><\/pre>\n\n\n\nAdjust the Nexus Memory Heap Size<\/h4>\n\n\n\n
The default minimum JVM heap for Nexus is 2037MB with maximum recommended being 4G.<\/p>\n\n\n\n
If you have less memory, you can reduce it by editing the file \/opt\/nexus\/bin\/nexus.vmoptions<\/strong><\/code> and setting a lower value, for demo purposes<\/strong>.<\/p>\n\n\n\nReplace the default values for the lines;<\/p>\n\n\n\n
-Xms2703m\n-Xmx2703m\n-XX:MaxDirectMemorySize=2703m\n...<\/code><\/pre>\n\n\n\nTo for example, to set it to 1024MB;<\/p>\n\n\n\n
-Xms1024m\n-Xmx1024m\n-XX:MaxDirectMemorySize=1024m<\/code><\/pre>\n\n\n\nSave and exit the file once you have made the changes. You can simply run the sed command below to replace the values;<\/p>\n\n\n\n
sed -i 's\/2703\/1024\/g' \/opt\/nexus\/bin\/nexus.vmoptions<\/code><\/pre>\n\n\n\nRunning Nexus Repository on Debian 11<\/h3>\n\n\n\nRunning Nexus in Standalone Mode<\/h4>\n\n\n\n
\/opt\/nexus\/bin\/nexus<\/strong><\/code> is the Nexus startup script.<\/p>\n\n\n\nTo run Nexus in standalone mode, you can run this command.<\/p>\n\n\n\n
However, you need to ensure that Nexus is run as nexus user.<\/p>\n\n\n\n
Therefore, edit the file \/opt\/nexus\/bin\/nexus.rc<\/strong><\/code> and uncomment the line, #run_as_user=\"\"<\/code><\/strong> and add nexus as the value.<\/p>\n\n\n\nsed -i 's\/#run_as_user=\"\"\/run_as_user=\"nexus\"\/' \/opt\/nexus\/bin\/nexus.rc<\/code><\/pre>\n\n\n\nChange the location of the Sonatype Work directory (Nexus data directory) to a location where nexus user has permissions to write.<\/p>\n\n\n\n
For example, in our setup, we set the home directory for Nexus as \/opt\/nexus<\/strong><\/code> and we gave nexus user ownership of this directory.<\/p>\n\n\n\nBy default, sonatype-work data directory is moved one directory up, hence, it is expected to be created under \/opt, which the nexus user has no permissions to write.<\/p>\n\n\n\n
Therefore, edit the \/opt\/nexus\/bin\/nexus.vmoptions<\/code><\/strong> and adjust the path of the Nexus directory (in the below settings, the directory is changed from ..\/sonatype-work<\/code><\/strong> to .\/sonatype-work<\/strong><\/code>).<\/p>\n\n\n\nsed -i 's|..\/sonatype|.\/sonatype|' \/opt\/nexus\/bin\/nexus.vmoptions<\/code><\/pre>\n\n\n\nYou can then run Nexus in standalone mode.<\/p>\n\n\n\n
sudo -u nexus \/opt\/nexus\/bin\/nexus start<\/code><\/pre>\n\n\n\nIt might take sometime for Nexus to start. While starting, tail the logs;<\/p>\n\n\n\n
tail -f \/opt\/nexus\/sonatype-work\/nexus3\/log\/nexus.log<\/code><\/pre>\n\n\n\n\n2021-10-21 20:33:43,243+0300 INFO [jetty-main-1] *SYSTEM com.softwarementors.extjs.djn.servlet.DirectJNgineServlet - Servlet GLOBAL configuration: registryConfiguratorClass=\n2021-10-21 20:33:43,705+0300 INFO [jetty-main-1] *SYSTEM com.softwarementors.extjs.djn.jscodegen.CodeFileGenerator - Creating source files for APIs...\n2021-10-21 20:33:46,340+0300 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.siesta.SiestaServlet - JAX-RS RuntimeDelegate: org.sonatype.nexus.siesta.internal.resteasy.SisuResteasyProviderFactory@22c27d33\n2021-10-21 20:33:46,747+0300 INFO [jetty-main-1] *SYSTEM org.jboss.resteasy.plugins.validation.i18n - RESTEASY008550: Unable to find CDI supporting ValidatorFactory. Using default ValidatorFactory\n2021-10-21 20:33:54,042+0300 INFO [periodic-8-thread-1] *SYSTEM org.sonatype.nexus.rapture.internal.HealthCheckCacheManager - Health check status changed from false to true for Lifecycle Phase\n2021-10-21 20:34:00,142+0300 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.siesta.SiestaServlet - Initialized\n2021-10-21 20:34:00,198+0300 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.repository.httpbridge.internal.ViewServlet - Initialized\n2021-10-21 20:34:01,234+0300 INFO [jetty-main-1] *SYSTEM org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.w.WebAppContext@27f305d1{Sonatype Nexus,\/,file:\/\/\/opt\/nexus\/public\/,AVAILABLE}\n2021-10-21 20:34:02,532+0300 INFO [jetty-main-1] *SYSTEM org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@c9a257e{HTTP\/1.1, (http\/1.1)}{0.0.0.0:8081}\n2021-10-21 20:34:02,534+0300 INFO [jetty-main-1] *SYSTEM org.eclipse.jetty.server.Server - Started @535009ms\n2021-10-21 20:34:02,564+0300 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - \n-------------------------------------------------\n\nStarted Sonatype Nexus OSS 3.35.0-02\n\n-------------------------------------------------\n<\/code><\/pre>\n\n\n\nNexus listens on TCP port 8081 by default;<\/p>\n\n\n\n
ss -altnp | grep :8081<\/code><\/pre>\n\n\n\nLISTEN 0 50 0.0.0.0:8081 0.0.0.0:* users:((\"java\",pid=2188,fd=699))<\/code><\/pre>\n\n\n\nYou should now be able to access Nexus web interface from browser.<\/p>\n\n\n\n
You can stop it by running the command;<\/p>\n\n\n\n
sudo -u nexus \/opt\/nexus\/bin\/nexus stop<\/code><\/pre>\n\n\n\nRunning Nexus Repository as a Systemd Service<\/h4>\n\n\n\n
To easily manage Nexus repository service, create a systemd service unit for it as shown below;<\/p>\n\n\n\n
\ncat > \/etc\/systemd\/system\/nexus.service << 'EOL'\n[Unit]\nDescription=nexus service\nAfter=network.target\n\n[Service]\nType=forking\nLimitNOFILE=65536\nExecStart=\/opt\/nexus\/bin\/nexus start\nExecStop=\/opt\/nexus\/bin\/nexus stop\nUser=nexus\nRestart=on-abort\n\n[Install]\nWantedBy=multi-user.target\nEOL\n<\/code><\/pre>\n\n\n\nReload the systemd manager configuration;<\/p>\n\n\n\n
systemctl daemon-reload<\/code><\/pre>\n\n\n\nStart and enable Nexus service to run on system reboot;<\/p>\n\n\n\n
systemctl enable --now nexus<\/code><\/pre>\n\n\n\nCheck the service status;<\/p>\n\n\n\n
systemctl status nexus<\/code><\/pre>\n\n\n\n\n\u25cf nexus.service - nexus service\n Loaded: loaded (\/etc\/systemd\/system\/nexus.service; enabled; vendor preset: enabled)\n Active: active (running) since Thu 2021-10-21 20:39:09 EAT; 4s ago\n Process: 2009 ExecStart=\/opt\/nexus\/bin\/nexus start (code=exited, status=0\/SUCCESS)\n Main PID: 2188 (java)\n Tasks: 15 (limit: 1133)\n Memory: 74.6M\n CPU: 1.364s\n CGroup: \/system.slice\/nexus.service\n \u2514\u25002188 \/usr\/lib\/jvm\/java-8-openjdk-amd64\/jre\/bin\/java -server -Dinstall4j.jvmDir=\/usr\/lib\/jvm\/java-8-openjdk-amd64\/jre -Dexe4j.moduleName=\/opt\/nexus\/bin\/nexus>\n\nOct 21 20:39:09 bullseye.kifarunix-demo.com systemd[1]: Starting nexus service...\nOct 21 20:39:09 bullseye.kifarunix-demo.com nexus[2009]: Starting nexus\nOct 21 20:39:09 bullseye.kifarunix-demo.com systemd[1]: Started nexus service.\n<\/code><\/pre>\n\n\n\nYou can as well check the logs for verification;<\/p>\n\n\n\n
tail -f \/opt\/nexus\/sonatype-work\/nexus3\/log\/nexus.log<\/code><\/pre>\n\n\n\nAccessing Nexus Repository Web Interface<\/h3>\n\n\n\n
You can now access Nexus repository from browser using the address http:\/\/server-IP-or-resolvable-hostname:8081<\/strong><\/code>.<\/p>\n\n\n\nIf UFW is running, you need to open port 8081 to allow external access.<\/p>\n\n\n\n
ufw allow 8081\/tcp<\/code><\/pre>\n\n\n\nNext, you can access from browser. Such an interface should welcome you.<\/p>\n\n\n\n
<\/figure>\n\n\n\nSetup Nexus Repository Manager<\/h3>\n\n\n\n
Click the sign in button at the top right corner. Login as admin<\/code><\/strong>.<\/p>\n\n\n\nThe password is located on the file, \/opt\/nexus\/sonatype-work\/nexus3\/admin.password<\/strong><\/code>.<\/p>\n\n\n\nTo get the password, just print the contents of the file.<\/p>\n\n\n\n
cat \/opt\/nexus\/sonatype-work\/nexus3\/admin.password<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n<\/a><\/p>\n\n\n\nOnce you logged in, click next<\/strong> to proceed to setup Nexus.<\/p>\n\n\n\n\n- Reset Nexus repository admin password<\/li>\n\n\n\n
- Configure anonymous access. You can choose to disable the anonymous access to secure Nexus repositories by requiring user to authenticate before they can browse through the repositories.<\/li>\n\n\n\n
- Finish the setup<\/li>\n<\/ol>\n\n\n\n
You can access Nexus repository manager settings by clicking on the gear icon;<\/p>\n\n\n\n
<\/figure>\n\n\n\n<\/a>You can go through the settings and make adjustments to suite your needs.<\/p>\n\n\n\nFurther Reading<\/h3>\n\n\n\n
Read more about Nexus and its setup on Nexus Repository Manager 3 documentation page.<\/p>\n\n\n\n
Nexus Repository Manager 3 documentation page<\/a><\/p>\n\n\n\nOther Tutorials<\/h3>\n\n\n\n
Install Nexus Repository Manager on Ubuntu 20.04<\/a><\/p>\n\n\n\n