๐ฆ Nexus Repository Manager on AlmaLinux: Central Hub for All Your Artifacts
Welcome to unified artifact management! ๐ Ready to centralize all your dependencies and packages? Nexus Repository Manager OSS is the free, powerful repository manager that stores and manages your Maven, npm, Docker, and 20+ other formats! Itโs the platform that becomes your single source of truth for all artifacts! Think of it as your universal package warehouse! ๐โจ
๐ค Why is Nexus Important?
Nexus revolutionizes artifact management! ๐ Hereโs why itโs amazing:
- ๐ฆ Universal Storage - Maven, npm, Docker, PyPI, and more!
- ๐ Proxy Repositories - Cache external dependencies!
- ๐ฏ Single Source - One place for all artifacts!
- ๐ Access Control - Fine-grained permissions!
- ๐ Repository Health - Monitor artifact quality!
- ๐ Completely Free - OSS edition forever!
Itโs like having your own private package hub! ๐ฐ
๐ฏ What You Need
Before building your repository hub, ensure you have:
- โ AlmaLinux 9 server
- โ Root or sudo access
- โ At least 4GB RAM (8GB recommended)
- โ 4 CPU cores minimum
- โ 50GB free disk space
- โ Java 8 or 11
- โ Love for organized artifacts! ๐ฆ
๐ Step 1: System Preparation - Getting Ready!
Letโs prepare AlmaLinux 9 for Nexus! ๐๏ธ
# Update system packages
sudo dnf update -y
# Install Java 8 (Nexus requirement)
sudo dnf install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
# Verify Java installation
java -version
# Should show: openjdk version "1.8.0_xxx"
# Create nexus user (no home directory needed)
sudo useradd -r -m -U -d /opt/nexus -s /bin/bash nexus
# Create necessary directories
sudo mkdir -p /opt/nexus
sudo mkdir -p /opt/sonatype-work
# Install required tools
sudo dnf install -y wget tar
Configure firewall for Nexus:
# Open Nexus port
sudo firewall-cmd --permanent --add-port=8081/tcp
# Open Docker registry port (if using)
sudo firewall-cmd --permanent --add-port=8082/tcp
sudo firewall-cmd --reload
# Verify ports
sudo firewall-cmd --list-ports
# Should show: 8081/tcp 8082/tcp
Configure system limits for Nexus:
# Increase file descriptors
sudo tee -a /etc/security/limits.conf << 'EOF'
nexus - nofile 65536
nexus - nproc 4096
EOF
# Create systemd override directory
sudo mkdir -p /etc/systemd/system/nexus.service.d/
# Set limits for systemd service
sudo tee /etc/systemd/system/nexus.service.d/override.conf << 'EOF'
[Service]
LimitNOFILE=65536
EOF
Perfect! System is ready! ๐ฏ
๐ง Step 2: Installing Nexus - The Manual Way!
Letโs install Nexus Repository Manager! ๐
Download and Extract Nexus:
# Download latest Nexus OSS (check for latest version)
cd /tmp
NEXUS_VERSION="3.61.0-02"
wget https://download.sonatype.com/nexus/3/nexus-${NEXUS_VERSION}-unix.tar.gz
# Extract to /opt
sudo tar -xzf nexus-${NEXUS_VERSION}-unix.tar.gz -C /opt/
# Rename for simplicity
sudo mv /opt/nexus-${NEXUS_VERSION} /opt/nexus/nexus
sudo mv /opt/sonatype-work /opt/nexus/
# Set ownership
sudo chown -R nexus:nexus /opt/nexus
# Verify installation
ls -la /opt/nexus/
# Should show: nexus and sonatype-work directories
Configure Nexus:
# Configure Nexus to run as nexus user
echo 'run_as_user="nexus"' | sudo tee /opt/nexus/nexus/bin/nexus.rc
# Configure JVM options
sudo vi /opt/nexus/nexus/bin/nexus.vmoptions
# Modify these settings:
# -Xms2048m
# -Xmx2048m
# -XX:MaxDirectMemorySize=3g
# -Djava.util.prefs.userRoot=/opt/nexus/sonatype-work/nexus3
Create Systemd Service:
# Create service file
sudo tee /etc/systemd/system/nexus.service << 'EOF'
[Unit]
Description=Nexus Repository Manager
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
User=nexus
Group=nexus
ExecStart=/opt/nexus/nexus/bin/nexus start
ExecStop=/opt/nexus/nexus/bin/nexus stop
Restart=on-failure
RestartSec=20
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd
sudo systemctl daemon-reload
# Enable and start Nexus
sudo systemctl enable nexus
sudo systemctl start nexus
# Check status
sudo systemctl status nexus
# Should show: active (running)
๐ Step 3: Initial Setup - Your Repository Hub!
Time to configure Nexus! ๐ฎ
Access Nexus:
# Wait for Nexus to fully start (2-3 minutes)
# Check logs
sudo tail -f /opt/nexus/sonatype-work/nexus3/log/nexus.log
# Look for: "Started Sonatype Nexus"
# Get initial admin password
sudo cat /opt/nexus/sonatype-work/nexus3/admin.password
# Save this password!
# Access Nexus
# URL: http://your-server-ip:8081
# Username: admin
# Password: (from admin.password file)
Setup Wizard:
- Login with admin credentials
- Change admin password immediately
- Configure Anonymous Access:
- Enable for public repositories
- Disable for private setup
- Complete setup
Dashboard shows:
- ๐ฆ Browse - View repositories
- ๐ง Administration - System settings
- ๐ Search - Find artifacts
- ๐ Support - Help resources
โ Step 4: Creating Repositories - Letโs Store Artifacts!
Time to create repositories for different formats! ๐ฏ
Create Maven Repository:
- Go to Administration โ Repositories
- Click โCreate repositoryโ
- Select โmaven2 (hosted)โ
- Configure:
- Name:
maven-releases
- Version policy:
Release
- Layout policy:
Strict
- Deployment policy:
Disable redeploy
- Name:
- Create repository
Create snapshots repository:
- Create another maven2 (hosted)
- Configure:
- Name:
maven-snapshots
- Version policy:
Snapshot
- Name:
Create npm Repository:
- Create repository โ npm (hosted)
- Configure:
- Name:
npm-private
- Deployment policy:
Allow redeploy
- Name:
- Create repository
Create Docker Registry:
- Create repository โ docker (hosted)
- Configure:
- Name:
docker-private
- HTTP port:
8082
- Enable Docker V1 API: โ (if needed)
- Name:
- Create repository
Create Proxy Repositories:
# Maven Central Proxy
# 1. Create repository โ maven2 (proxy)
# 2. Configure:
# - Name: maven-central
# - Remote URL: https://repo1.maven.org/maven2/
# - Use certificates: unchecked
# npm Registry Proxy
# 1. Create repository โ npm (proxy)
# 2. Configure:
# - Name: npm-registry
# - Remote URL: https://registry.npmjs.org
# Docker Hub Proxy
# 1. Create repository โ docker (proxy)
# 2. Configure:
# - Name: docker-hub
# - Remote URL: https://registry-1.docker.io
# - Docker Index: Use Docker Hub
Create Group Repositories:
- Create repository โ maven2 (group)
- Configure:
- Name:
maven-public
- Member repositories:
- maven-releases
- maven-snapshots
- maven-central
- Name:
- Create repository
๐ Step 5: Using Nexus - Upload and Download!
Letโs use our repositories! ๐ฏ
Configure Maven:
<!-- Add to ~/.m2/settings.xml -->
<settings>
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>your-password</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>your-password</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://your-server-ip:8081/repository/maven-public/</url>
</mirror>
</mirrors>
</settings>
Deploy to Nexus:
<!-- Add to pom.xml -->
<distributionManagement>
<repository>
<id>nexus-releases</id>
<url>http://your-server-ip:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://your-server-ip:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<!-- Deploy with: mvn deploy -->
Configure npm:
# Set registry for your scope
npm config set @mycompany:registry http://your-server-ip:8081/repository/npm-private/
# Login to Nexus
npm login --registry=http://your-server-ip:8081/repository/npm-private/
# Username: admin
# Password: your-password
# Email: [email protected]
# Publish package
npm publish --registry=http://your-server-ip:8081/repository/npm-private/
# Install from Nexus
npm install @mycompany/package --registry=http://your-server-ip:8081/repository/npm-public/
Configure Docker:
# Configure Docker for insecure registry
sudo vi /etc/docker/daemon.json
{
"insecure-registries": ["your-server-ip:8082"]
}
# Restart Docker
sudo systemctl restart docker
# Login to Nexus Docker registry
docker login your-server-ip:8082
# Username: admin
# Password: your-password
# Tag and push image
docker tag myapp:latest your-server-ip:8082/myapp:latest
docker push your-server-ip:8082/myapp:latest
# Pull from Nexus
docker pull your-server-ip:8082/myapp:latest
๐ฎ Quick Examples
Example 1: CI/CD Integration
// Jenkins Pipeline example
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'mvn clean package'
}
}
stage('Deploy to Nexus') {
steps {
sh '''
mvn deploy:deploy-file \
-DgroupId=com.example \
-DartifactId=myapp \
-Dversion=${BUILD_NUMBER} \
-Dpackaging=jar \
-Dfile=target/myapp.jar \
-DrepositoryId=nexus-releases \
-Durl=http://nexus:8081/repository/maven-releases/
'''
}
}
}
}
Example 2: Cleanup Policies
# Create cleanup policy via API
curl -u admin:password -X POST \
"http://your-server-ip:8081/service/rest/v1/cleanup-policies" \
-H "Content-Type: application/json" \
-d '{
"name": "cleanup-snapshots",
"format": "maven2",
"mode": "delete",
"criteria": {
"lastBlobUpdated": "30",
"isPrerelease": "true"
}
}'
# Apply to repository
# Go to repository settings โ Cleanup policies
# Select: cleanup-snapshots
Example 3: Repository Health Check
# Create scheduled task for health check
# Administration โ System โ Tasks โ Create task
# Type: "Repository Health Check"
# Repository: maven-public
# Schedule: Daily at 2 AM
# Via REST API
curl -u admin:password \
"http://your-server-ip:8081/service/rest/v1/repositories/maven-public/health-check"
๐จ Fix Common Problems
Problem 1: Nexus Wonโt Start
Symptom: Service fails or stuck starting ๐ฐ
Fix:
# Check logs
sudo tail -n 100 /opt/nexus/sonatype-work/nexus3/log/nexus.log
# Common issue: Not enough memory
free -h
# Increase memory in nexus.vmoptions
# Check permissions
ls -la /opt/nexus/
# Should be owned by nexus user
# Manual start for debugging
sudo -u nexus /opt/nexus/nexus/bin/nexus run
# Check Java version
java -version
# Must be Java 8 or 11
Problem 2: Cannot Upload Artifacts
Symptom: 401 Unauthorized or 403 Forbidden ๐
Fix:
# Check credentials in settings.xml
cat ~/.m2/settings.xml
# Verify repository permissions
# Administration โ Security โ Users
# Check user has nx-repository-admin privilege
# Check deployment policy
# Repository settings โ Deployment policy
# Should be "Allow redeploy" for snapshots
# Test with curl
curl -u admin:password \
--upload-file myapp.jar \
"http://your-server-ip:8081/repository/maven-releases/com/example/myapp/1.0/myapp-1.0.jar"
Problem 3: Disk Space Issues
Symptom: Storage full, uploads failing ๐พ
Fix:
# Check disk usage
df -h /opt/nexus
# Run cleanup task
# Administration โ System โ Tasks
# Run: "Admin - Compact blob store"
# Delete old snapshots
# Create cleanup policy (see Example 2)
# Move blob store to larger disk
sudo systemctl stop nexus
sudo mv /opt/nexus/sonatype-work/nexus3/blobs /new/location/
sudo ln -s /new/location/blobs /opt/nexus/sonatype-work/nexus3/blobs
sudo systemctl start nexus
๐ Simple Commands Summary
Task | Command/Location | Purpose |
---|---|---|
Start Nexus | sudo systemctl start nexus | Start service |
Stop Nexus | sudo systemctl stop nexus | Stop service |
View logs | tail -f /opt/nexus/sonatype-work/nexus3/log/nexus.log | Monitor logs |
Initial password | cat /opt/nexus/sonatype-work/nexus3/admin.password | First login |
Browse repos | Browse โ Components | View artifacts |
Upload artifact | Use Maven/npm/Docker client | Deploy artifacts |
Search | Search โ Components | Find artifacts |
Tasks | Administration โ System โ Tasks | Maintenance |
Cleanup | Administration โ Cleanup policies | Space management |
๐ก Tips for Success
๐ Performance Optimization
Make Nexus super fast:
# Increase JVM heap
sudo vi /opt/nexus/nexus/bin/nexus.vmoptions
# -Xms4g
# -Xmx4g
# -XX:MaxDirectMemorySize=6g
# Enable G1 garbage collector
# -XX:+UseG1GC
# -XX:MaxGCPauseMillis=200
# Database optimization
# Administration โ System โ Capabilities
# Create: "Datastore JDBC" capability
# Configure PostgreSQL for better performance
# Restart Nexus
sudo systemctl restart nexus
๐ Security Best Practices
Keep Nexus secure:
- Enable HTTPS - Use SSL certificates! ๐
- LDAP Integration - Central authentication! ๐ฅ
- Content Selectors - Fine-grained access! ๐
- Realms - Enable security features! ๐ก๏ธ
- Regular updates - Keep Nexus updated! ๐ฆ
# Setup HTTPS with reverse proxy
sudo dnf install -y nginx
cat << 'EOF' | sudo tee /etc/nginx/conf.d/nexus.conf
server {
listen 443 ssl;
server_name nexus.example.com;
ssl_certificate /etc/ssl/certs/nexus.crt;
ssl_certificate_key /etc/ssl/private/nexus.key;
client_max_body_size 1G;
location / {
proxy_pass http://localhost:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto "https";
}
}
EOF
sudo systemctl restart nginx
๐ Monitoring and Backup
Keep Nexus healthy:
# Backup script
cat << 'EOF' > /usr/local/bin/backup-nexus.sh
#!/bin/bash
BACKUP_DIR="/backup/nexus"
DATE=$(date +%Y%m%d)
mkdir -p $BACKUP_DIR
# Stop Nexus
sudo systemctl stop nexus
# Backup data
tar -czf $BACKUP_DIR/nexus-data-$DATE.tar.gz /opt/nexus/sonatype-work/nexus3
# Start Nexus
sudo systemctl start nexus
# Keep only last 7 backups
find $BACKUP_DIR -name "*.tar.gz" -mtime +7 -delete
echo "Backup completed!"
EOF
chmod +x /usr/local/bin/backup-nexus.sh
# Add to cron: 0 2 * * * /usr/local/bin/backup-nexus.sh
๐ What You Learned
Youโre now a Nexus Repository expert! ๐ Youโve successfully:
- โ Installed Nexus on AlmaLinux 9
- โ Created multiple repository types
- โ Configured Maven, npm, and Docker
- โ Set up proxy repositories
- โ Implemented cleanup policies
- โ Integrated with CI/CD
- โ Mastered artifact management
Your repository hub is production-ready! ๐ฆ
๐ฏ Why This Matters
Nexus transforms artifact management! With your repository manager, you can:
- ๐ฆ Centralize everything - One source of truth!
- ๐ Speed up builds - Local artifact caching!
- ๐ Control access - Who gets what artifacts!
- ๐ Track usage - Know whatโs being used!
- ๐ฐ Save bandwidth - Cache external dependencies!
Youโre not just storing artifacts - youโre creating a robust supply chain for your entire development process! Every dependency is managed, every artifact is tracked! ๐ญ
Keep building, keep managing, and remember - with Nexus, artifact chaos becomes organized bliss! โญ
May your builds be fast and your artifacts always available! ๐๐ฆ๐