Install Nexus on RHEL 8 with JDK 21

To install Nexus Repository Manager on Red Hat 8 with OpenJDK 21, you’ll largely follow the same steps as before, with a key modification for the Java installation and the JAVA_HOME path in the systemd service file.

Here’s the updated guide:

System Requirements (General Guidelines for Nexus Repository Manager 3):

  • Operating System: Red Hat Enterprise Linux 8 (64-bit).
  • CPUs: Minimum 4, Recommended 8.
  • RAM: Minimum 8GB (for small profiles), 16GB or more for larger deployments. Nexus typically needs about two-thirds of available RAM.
  • Disk Space: Varies depending on usage. You’ll need at least 4GB for the application and significant space for your repositories (blob storage).
  • Java: Nexus Repository Manager 3 requires Java 17 or newer. OpenJDK 21 is fully compatible and recommended for the latest Nexus versions.

Installation Steps:

1. Update System and Install Prerequisites:

Ensure your system is up to date and install wget.

sudo dnf update -y
sudo dnf install wget -y

2. Install Java (OpenJDK 21):

This is the main change from the previous instructions.

sudo dnf install java-21-openjdk-devel -y

Verify the Java version:

java -version

You should see output similar to:

openjdk version "21.0.x" ...

3. Create a Dedicated User for Nexus:

It’s a security best practice to run Nexus as a non-root user.

sudo adduser nexus

4. Create Installation and Data Directories:

Create a directory for the Nexus application and a separate directory for its data.

sudo mkdir /opt/nexus
sudo mkdir /opt/nexus-data

5. Download and Extract Nexus Repository Manager:

Get the latest Nexus Repository Manager 3 tarball.

cd /opt
sudo wget -O nexus.tar.gz https://download.sonatype.com/nexus/3/latest-unix.tar.gz
sudo tar -xvf nexus.tar.gz

Rename the extracted directory to something simpler (e.g., nexus). The extracted directory will have a name like nexus-3.x.x-xx.

sudo mv nexus-3.* nexus

6. Configure Permissions:

Change the ownership of the Nexus installation and data directories to the nexus user.

sudo chown -R nexus:nexus /opt/nexus
sudo chown -R nexus:nexus /opt/nexus-data

7. Configure Nexus nexus.rc and nexus-default.properties:

  • Set run_as_user: Edit the nexus.rc file to specify the user that will run Nexus.

    sudo vi /opt/nexus/bin/nexus.rc
    

    Uncomment the run_as_user line and set it to nexus:

    run_as_user="nexus"
    
  • Set nexus-data directory: Edit the nexus-default.properties file to point to your dedicated data directory.

    sudo vi /opt/nexus/etc/nexus-default.properties
    

    Find the line for nexus-work and modify it:

    # uncomment and replace the below if you wish to use a custom data directory
    # nexus-work=${karaf.data}/nexus3
    nexus-work=/opt/nexus-data
    

    You might also want to adjust application-host (default 0.0.0.0) and application-port (default 8081) if needed.

8. Configure System Limits:

Nexus requires higher open file limits.

sudo vi /etc/security/limits.conf

Add these lines at the end of the file:

nexus - nofile 65536
nexus - nproc 65536

9. Create a Systemd Service File for Nexus:

This is another point of change: ensuring JAVA_HOME points to OpenJDK 21.

sudo vi /etc/systemd/system/nexus.service

Add the following content:

[Unit]
Description=Nexus Repository Manager
After=network.target

[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Group=nexus
Restart=on-failure
Environment=JAVA_HOME=/usr/lib/jvm/java-21-openjdk-21.0.x.x-x.el8.x86_64 # <<< Adjust this path

[Install]
WantedBy=multi-user.target

Important: The Environment=JAVA_HOME line needs to point to your actual OpenJDK 21 installation path. You can find this path by running sudo alternatives --config java and noting the path of the Java 21 entry, or typically it’s /usr/lib/jvm/java-21-openjdk/ followed by a version specific directory. For instance, on Red Hat 8, it might look like /usr/lib/jvm/java-21-openjdk-21.0.1.0.12-2.el8.x86_64 (the exact version numbers might differ).

Reload the systemd daemon to recognize the new service:

sudo systemctl daemon-reload

10. Start and Enable Nexus Service:

sudo systemctl start nexus
sudo systemctl enable nexus

11. Check Nexus Status and Logs:

sudo systemctl status nexus
tail -f /opt/nexus-data/log/nexus.log

Look for messages indicating Nexus has started and is listening on port 8081.

12. Configure Firewall (if applicable):

If you have a firewall enabled, open port 8081.

sudo firewall-cmd --permanent --add-port=8081/tcp
sudo firewall-cmd --reload

13. Access the Nexus Web Interface:

Open a web browser and navigate to: http://your_server_ip_or_hostname:8081

14. Initial Login and Setup:

  • Retrieve Admin Password: The first time Nexus starts, it generates a unique admin password.

    sudo cat /opt/nexus-data/admin.password
    
  • Log in with the username admin and the retrieved password.

  • You will be prompted to change the default admin password immediately.

  • Follow the on-screen wizard to complete the initial setup.

Your Nexus Repository Manager is now installed and running with OpenJDK 21 on Red Hat 8!

Leave a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Scroll to Top