{"id":928,"date":"2021-04-25T01:54:00","date_gmt":"2021-04-25T01:54:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=928"},"modified":"2021-04-25T01:54:00","modified_gmt":"2021-04-25T01:54:00","slug":"how-to-install-latest-sonatype-nexus-3-on-linux","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=928","title":{"rendered":"How To Install Latest Sonatype Nexus 3 on Linux (Redhat\/Centos\/ec2)"},"content":{"rendered":"<p>Sonatype Nexus is one of the best open-source artifact management tools. It is some tool that you cannot avoid in your <a href=\"https:\/\/devopscube.com\/jenkins-pipeline-as-code\/\" rel=\"noreferrer noopener\">CI\/CD pipeline<\/a>. It effectively manages deployable artifacts.<\/p>\n<h3 id=\"sonatype-nexus-system-requirements\">Sonatype Nexus System Requirements<\/h3>\n<ol>\n<li>Minimum 1 VCPU &amp; 2 GB Memory<\/li>\n<li>Server firewall opened for port 22 &amp; 8081<\/li>\n<li>OpenJDK 17<\/li>\n<li>All Nexus processes should run as a non-root nexus user.<\/li>\n<\/ol>\n<div class=\"kg-card kg-callout-card kg-callout-card-grey\">\n<div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Note<\/strong><\/b>: For production setup, please consider minimum production hardware requirements based on the nexus usage and data storage. Check out the <a href=\"https:\/\/help.sonatype.com\/repomanager3\/installation\/system-requirements?ref=devopscube.com\" rel=\"noreferrer noopener\">official system requirements document <\/a>for detailed information<\/div>\n<\/div>\n<h2 id=\"sonatype-nexus-3-on-linux-ec2\">Sonatype Nexus 3 on Linux ec2<\/h2>\n<p>This article guides you to install and configure Sonatype Nexus 3 in a secure way on an ec2 Linux System.<\/p>\n<div class=\"kg-card kg-callout-card kg-callout-card-grey\">\n<div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Note<\/strong><\/b>: This was tested on a Redhat machine and it will work on Centos or related Linux flavors as well.<\/div>\n<\/div>\n<p><strong>Step 1:<\/strong> Login to your Linux server and update the yum packages. Also install required utilities.<\/p>\n<pre><code>sudo yum update -y\nsudo yum install wget -y<\/code><\/pre>\n<p><strong>Step 2:<\/strong> Install OpenJDK 1.8<\/p>\n<pre><code>sudo yum install java-17-openjdk -y<\/code><\/pre>\n<p><strong>Step 3:<\/strong> Create a directory named app and cd into the directory.<\/p>\n<pre><code>sudo mkdir \/app &amp;&amp; cd \/app<\/code><\/pre>\n<p><strong>Step 4:<\/strong> Download the latest nexus. You can get the latest download links fo for nexus <a href=\"https:\/\/help.sonatype.com\/repomanager3\/download?ref=devopscube.com\" rel=\"noreferrer noopener\">from here<\/a>.<\/p>\n<pre><code>sudo wget -O nexus.tar.gz https:\/\/download.sonatype.com\/nexus\/3\/latest-unix.tar.gz<\/code><\/pre>\n<p>Untar the downloaded file.<\/p>\n<pre><code>sudo tar -xvf nexus.tar.gz<\/code><\/pre>\n<p>Rename the untared file to nexus.<\/p>\n<pre><code>sudo mv nexus-3* nexus<\/code><\/pre>\n<p><strong>Step 5:<\/strong> As a good security practice, it is not advised to run nexus service with root privileges. So create a new user named <code>nexus<\/code> to run the nexus service.<\/p>\n<pre><code>sudo adduser nexus<\/code><\/pre>\n<p>Change the ownership of nexus files and nexus data directory to nexus user.<\/p>\n<pre><code>sudo chown -R nexus:nexus \/app\/nexus\nsudo chown -R nexus:nexus \/app\/sonatype-work<\/code><\/pre>\n<p><strong>Step 6:<\/strong> Open <code>\/app\/nexus\/bin\/nexus.rc<\/code> file<\/p>\n<pre><code>sudo vi  \/app\/nexus\/bin\/nexus.rc<\/code><\/pre>\n<p>Uncomment run_as_user parameter and set it as following.<\/p>\n<pre><code>run_as_user=\"nexus\"<\/code><\/pre>\n<p><strong>Step 7: <\/strong>If you want to change the default nexus data directory, open the nexus properties file and change the data directory <code>-Dkaraf.data<\/code> parameter to a preferred location as shown below.  If you don&#8217;t specify anything, by default nexus data directory will be set to <code>\/app\/sonatype-work\/nexus3<\/code><\/p>\n<div class=\"kg-card kg-callout-card kg-callout-card-grey\">\n<div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Tip<\/strong><\/b>: For production setup, it is is always better to mount the nexus data directory to a separate data disk attached to the server. So that backup and restore can be done easily.<\/div>\n<\/div>\n<pre><code>sudo vi \/app\/nexus\/bin\/nexus.vmoptions<\/code><\/pre>\n<p>An example configuration is shown below.<\/p>\n<pre><code>-Xms2703m\n-Xmx2703m\n-XX:MaxDirectMemorySize=2703m\n-XX:+UnlockDiagnosticVMOptions\n-XX:+UnsyncloadClass\n-XX:+LogVMOutput\n-XX:LogFile=..\/sonatype-work\/nexus3\/log\/jvm.log\n-XX:-OmitStackTraceInFastThrow\n-Djava.net.preferIPv4Stack=true\n-Dkaraf.home=.\n-Dkaraf.base=.\n-Dkaraf.etc=etc\/karaf\n-Djava.util.logging.config.file=etc\/karaf\/java.util.logging.properties\n-Dkaraf.data=\/nexus\/nexus-data\n-Djava.io.tmpdir=..\/sonatype-work\/nexus3\/tmp\n-Dkaraf.startLocalConsole=false<\/code><\/pre>\n<h2 id=\"running-nexus-as-a-system-service\">Running Nexus as a System Service<\/h2>\n<p>It is better to have <code>systemd<\/code> entry to manage nexus using <code>systemctl<\/code>. Follow the steps given below for adding nexus as a <code>systemd<\/code> service.<\/p>\n<p>Create a nexus systemd unit file.<\/p>\n<pre><code>sudo vi \/etc\/systemd\/system\/nexus.service<\/code><\/pre>\n<p>Add the following contents to the unit file.<\/p>\n<pre><code>[Unit]\nDescription=nexus service\nAfter=network.target\n\n[Service]\nType=forking\nLimitNOFILE=65536\nUser=nexus\nGroup=nexus\nExecStart=\/app\/nexus\/bin\/nexus start\nExecStop=\/app\/nexus\/bin\/nexus stop\nUser=nexus\nRestart=on-abort\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<h2 id=\"manage-nexus-service\">Manage Nexus Service<\/h2>\n<p>Now we have all the configurations in place to run nexus.<\/p>\n<p>Execute the following command to add nexus service to boot.<\/p>\n<pre><code>sudo chkconfig nexus on<\/code><\/pre>\n<p>To start the Nexus service, use the following command. If you are having trouble starting nexus, please check the troubleshooting section below.<\/p>\n<pre><code>sudo systemctl start nexus<\/code><\/pre>\n<p>The above command will start the nexus service on port <code>8081<\/code>. To access the nexus dashboard, visit http:\/\/:8081. You will be able to see the nexus homepage as shown below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/nexus-setup-1.jpg\" class=\"kg-image\" alt=\"nexus 3 homepage\" loading=\"lazy\" width=\"1362\" height=\"634\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/nexus-setup-1.jpg 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/nexus-setup-1.jpg 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/nexus-setup-1.jpg 1362w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>To log in, use the default username and password.<\/p>\n<p>Default username is <code>admin<\/code><\/p>\n<p>You can find the default admin password in \/<code>app\/sonatype-work\/nexus3\/admin.password<\/code> file. The path will be shown in the login screen as show below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/nexus-password-min-1.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"812\" height=\"542\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/nexus-password-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/nexus-password-min-1.png 812w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<pre><code>cat \/app\/sonatype-work\/nexus3\/admin.password<\/code><\/pre>\n<p>Once you login, you will be prompted to reset the password.<\/p>\n<p>For stopping nexus, execute<\/p>\n<pre><code>sudo systemctl stop nexus<\/code><\/pre>\n<p>For restarting nexus,<\/p>\n<pre><code>sudo systemctl restart nexus<\/code><\/pre>\n<h2 id=\"sonatype-nexus-not-starting-troubleshooting\">Sonatype Nexus not Starting [Troubleshooting]<\/h2>\n<p>Sometimes, if the server is enabled with SELINUX, you might get the following error. (Commonly on Centos Servers)<\/p>\n<pre><code>Job for nexus.service failed because the control process exited with error code.\nSee \"systemctl status nexus.service\" and \"journalctl -xe\" for details.<\/code><\/pre>\n<p>Execute the following command and see the actual error.<\/p>\n<pre><code>journalctl -xe<\/code><\/pre>\n<p>Check the output for the following SELINUX issue.<\/p>\n<pre><code>SELinux is preventing \/usr\/lib\/systemd\/systemd from execute access on the file nexus.<\/code><\/pre>\n<p>To rectify this issue, add a SELinux policy to allow Systemd to access the nexus binary in path <code>\/app\/nexus\/bin\/nexus<\/code> using the following command.<\/p>\n<pre><code>sudo chcon -R -t bin_t \/app\/nexus\/bin\/nexus<\/code><\/pre>\n<p>Now, start the Nexus server again.<\/p>\n<pre><code>sudo systemctl start nexus<\/code><\/pre>\n<h2 id=\"faqs\">FAQs<\/h2>\n<h3 id=\"how-to-check-the-nexus-version-in-linux\">How to check the Nexus version in Linux?<\/h3>\n<p>You can find the Nexus version from the Dashboard. Also, if you want to find the version from the Linux command line, execute the following command.<br \/><code>curl --<strong>include<\/strong> --silent http:\/\/localhost:8081\/ | grep Server<\/code><\/p>\n<h3 id=\"how-to-start-nexus-in-linux\">How to start Nexus in Linux?<\/h3>\n<p>Nexus binary comes as an executable. You can use the binary path to start nexus. For background execution,  you can create a systemd file with nexus configurations.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/how-to-install-latest-sonatype-nexus-3-on-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Install Latest Sonatype Nexus 3 on Linux (Redhat\/Centos\/ec2) \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/how-to-install-latest-sonatype-nexus-3-on-linux\/<\/p>\n","protected":false},"author":1,"featured_media":929,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-928","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=928"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/928\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/929"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}