Day 71 : Setting Up Nexus Repository

Today, I set up Nexus Repository Manager 3 on CentOS. Nexus acts as an artifact repository that stores build outputs (JARs, WARs, Docker images, etc.) and integrates seamlessly into the CI/CD pipeline. It’s a critical part of software delivery, ensuring versioned and reliable deployments.


🔧 Why Nexus?

  • Stores artifacts generated by CI builds (e.g., Maven, Gradle).

  • Provides artifact versioning and dependency management.

  • Improves team collaboration by centralizing builds.

  • Secures software supply chain with access controls.


📜 Setup Script

Here’s the automated script I used to provision Nexus setup on CentOS on AWS:

#!/bin/bash

# Import Amazon Corretto repo for Java
sudo rpm --import https://yum.corretto.aws/corretto.key
sudo curl -L -o /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo

# Install Java 17 and wget
sudo yum install -y java-17-amazon-corretto-devel wget -y

# Prepare directories
mkdir -p /opt/nexus/
mkdir -p /tmp/nexus/
cd /tmp/nexus/

# Download and extract Nexus
NEXUSURL="https://download.sonatype.com/nexus/3/nexus-unix-x86-64-3.78.0-14.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

# Create nexus user
useradd nexus
chown -R nexus.nexus /opt/nexus

# Create systemd service
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

# Set run user
echo 'run_as_user="nexus"' > /opt/nexus/$NEXUSDIR/bin/nexus.rc

# Enable and start nexus
systemctl daemon-reload
systemctl start nexus
systemctl enable nexus

🖥️ Access Nexus

Once Nexus is installed and running, you can access it via:

👉 http://<server-ip>:8081

Default credentials:

  • Username: admin

  • Password: stored in /opt/nexus/sonatype-work/nexus3/admin.password


🌟 Key Takeaways

  • Nexus is an essential tool for storing and managing build artifacts.

  • Setting it up on CentOS with Amazon Corretto JDK 17 ensures compatibility with modern builds.

  • With Nexus integrated into Jenkins pipelines, we can securely manage application artifacts.

Next, I’ll integrate Nexus into my CI/CD pipeline for artifact uploads and deployments.

0
Subscribe to my newsletter

Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaharyar Shakir
Shaharyar Shakir