Installing Nexus on Cent OS

Fri Mar 7, 2025

In this document we will see a step by step guide on how to install Nexus on Cent OS

What is Nexus ?

Nexus Repository Manager is a repository manager used for storing and managing software artifacts. It serves as a central hub for storing binary artifacts such as JAR files, Docker images, npm packages, Maven artifacts, and more. Nexus provides a secure, reliable, and scalable solution for managing dependencies and artifacts throughout the software development lifecycle.

Steps to run Nexus on CentOS:

  1. Launch a t2 medium AWS EC2 instance and choose OS as CentOS 9 or your choice of CentOS 9 and login to it.
  2. If you are launching instance on AWS add the below script as part of user data.
        
    #!/bin/bash
    yum install java-1.8.0-openjdk.x86_64 wget -y
    mkdir -p /opt/nexus/
    mkdir -p /tmp/nexus/ `
    cd /tmp/nexus/
    NEXUSURL="https://download.sonatype.com/nexus/3/latest-unix.tar.gz"
    wget $NEXUSURL -O nexus.tar.gz
    sleep 10
    EXTOUT=`tar xzvf nexus.tar.gz`
    NEXUSDIR=`echo $EXTOUT | cut -d '/' -f1`
    sleep 5
    rm -rf /tmp/nexus/nexus.tar.gz
    cp -r /tmp/nexus/* /opt/nexus/
    sleep 5
    useradd nexus
    chown -R nexus.nexus /opt/nexus
    cat <<EOT>> /etc/systemd/system/nexus.service
    [Unit]
    Description=nexus service
    After=network.target
    [Service]
    Type=forking
    LimitNOFILE=65536
    ExecStart=/opt/nexus/$NEXUSDIR/bin/nexus start
    ExecStop=/opt/nexus/$NEXUSDIR/bin/nexus stop
    User=nexus
    Restart=on-abort
    [Install]
    WantedBy=multi-user.target

    EOT

    echo 'run_as_user="nexus"' > /opt/nexus/$NEXUSDIR/bin/nexus.rc
    systemctl daemon-reload
    systemctl start nexus
    systemctl enable nexus

  1. If you are using any other system of CentOS run the below commands one by one.
  2. Install Java in CentOSyum install java-1.8.0-openjdk.x86_64 wget -y
  3. Make a directory nexus inside /opt and /tmp using below commandsmkdir -p /opt/nexus mkdir -p /tmp/nexus
  4. Download latest nexus inside /tmp/nexuswget https://download.sonatype.com/nexus/3/latest-unix.tar.gz -O nexus.tar.gz
  5. Untar it using below commandtar xzvf nexus.tar.gz
  6. Delete the tar file now and copy all the contents to /opt/nexus using below commandsrm -rf /tmp/nexus/nexus.tar.gz cp -r /tmp/nexus/* /opt/nexus
  7. Create a nexus user using below commanduseradd nexus
  8. Provide nexus user permission to /opt/nexus directory by following below commandchown -R nexus.nexus /opt/nexus/

  1. Create a service for nexus by adding nexus.service file inside /etc/systemd/system by running below commandvim /etc/systemd/system/nexus.serviceand add below content [Unit]
    Description=nexus service
    After=network.target[Service]
    Type=forking
    LimitNOFILE=65536
    ExecStart=/opt/nexus/$NEXUSDIR/bin/nexus start
    ExecStop=/opt/nexus/$NEXUSDIR/bin/nexus stop
    User=nexus
    Restart=on-abort[Install]
    WantedBy=multi-user.target
  2. Edit nexus.rc file inside /opt/nexus/nexus3*/nexus.rc and uncomment the line run_as_user and add nexus . The content should berun_as_user="nexus"save and quit.
  3. Reload system managersystemctl daemon-reload
  4. Start nexus service
systemctl start nexus
  1. Enable nexus service
systemctl enable nexus
  1. If all good then open your favorite browser and add http://host-ip:port, you should see something like below

  1. Click on login option at the right top corner and you will see that username is admin and password can be retrieved from given location. Cat the file and get the password
sudo cat /opt/nexus/sonatype-work/nexus3/admin.password

Chinmay Biswal
Solution Architect