Installing Nexus on Cent OS - cloudeguru/How-To-Install GitHub Wiki

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:
-
Launch a t2 medium AWS EC2 instance and choose OS as CentOS 9 or your choice of CentOS 9 and login to it.
-
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
-
If you are using any other system of CentOS run the below commands one by one.
-
Install Java in CentOS
yum install java-1.8.0-openjdk.x86_64 wget -y
-
Make a directory nexus inside /opt and /tmp using below commands
mkdir -p /opt/nexus mkdir -p /tmp/nexus
-
Download latest nexus inside /tmp/nexus
wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz -O nexus.tar.gz
-
Untar it using below command
tar xzvf nexus.tar.gz
-
Delete the tar file now and copy all the contents to /opt/nexus using below commands
rm -rf /tmp/nexus/nexus.tar.gz cp -r /tmp/nexus/* /opt/nexus
-
Create a nexus user using below command
useradd nexus
-
Provide nexus user permission to /opt/nexus directory by following below command
chown -R nexus.nexus /opt/nexus/
-
Create a service for nexus by adding nexus.service file inside /etc/systemd/system by running below command
vim /etc/systemd/system/nexus.service
and 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 -
Edit nexus.rc file inside /opt/nexus/nexus3*/nexus.rc and uncomment the line run_as_user and add nexus . The content should be
run_as_user="nexus"
save and quit.
-
Reload system manager
systemctl daemon-reload
-
Start nexus service
systemctl start nexus
- Enable nexus service
systemctl enable nexus
- If all good then open your favorite browser and add http://host-ip:port, you should see something like below

- 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
