·12 min read·

How to Setup Nexus Repository on Ubuntu

A complete guide to deploying Sonatype Nexus Repository Manager — your private registry for Docker images, npm packages, Maven artifacts, and more.

NexusRegistryDockerDevOps

Nexus Repository Architecture

Universal Artifact Management

CI/CDPipeline
Push/Pull
NexusRepository
Proxy
Docker HubUpstream

What is Nexus Repository?

Sonatype Nexus Repository Manager is a universal artifact repository that stores and manages your build artifacts and dependencies. It supports Docker, npm, Maven, PyPI, NuGet, Helm, and many more formats — all from a single server.

Universal

Supports 20+ repository formats — Docker, npm, Maven, PyPI, Helm, apt, yum, and more.

Proxy & Cache

Proxy remote registries (Docker Hub, npmjs) and cache artifacts locally for faster builds.

Private Hosting

Host your private Docker images, internal packages, and proprietary artifacts securely.

Prerequisites

  • Ubuntu 22.04 or 24.04 LTS server
  • Minimum 4 GB RAM (8 GB recommended)
  • Java 8 or 11 (OpenJDK)
  • Root or sudo access
  • Ports: 8081 (Web UI), 8082 (Docker hosted), 8083 (Docker proxy)

Step 1: Install Java

# Install OpenJDK 11

sudo apt-get update sudo apt-get install -y openjdk-11-jdk

# Verify

java -version

Step 2: Download & Install Nexus

# Download latest Nexus

cd /opt sudo wget https://download.sonatype.com/nexus/3/nexus-3.72.0-04-unix.tar.gz

# Extract

sudo tar -xvzf nexus-3.72.0-04-unix.tar.gz sudo mv nexus-3.72.0-04 nexus

# Create nexus user

sudo useradd -r -m -d /opt/nexus -s /bin/bash nexus sudo chown -R nexus:nexus /opt/nexus sudo chown -R nexus:nexus /opt/sonatype-work

# Set run-as user

echo 'run_as_user="nexus"' | sudo tee /opt/nexus/bin/nexus.rc

Step 3: Create Systemd Service

# Create service file

sudo tee /etc/systemd/system/nexus.service <<EOF
[Unit]
Description=Sonatype Nexus Repository Manager
After=network.target

[Service]
Type=forking
LimitNOFILE=65536
User=nexus
Group=nexus
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
Restart=on-abort

[Install]
WantedBy=multi-user.target
EOF

# Start and enable

sudo systemctl daemon-reload sudo systemctl start nexus sudo systemctl enable nexus sudo systemctl status nexus

Note: Nexus takes 1-2 minutes to start. Wait, then check http://your-ip:8081

Step 4: Initial Login

# Get the admin password

sudo cat /opt/sonatype-work/nexus3/admin.password
1

Open Web UI

Navigate to http://your-server-ip:8081

2

Login

Username: admin / Password: from the file above

3

Change Password

Follow the setup wizard to set a new admin password and configure anonymous access.

Step 5: Setup Docker Registry

Create three Docker repositories: hosted (your images), proxy (cache Docker Hub), and group (combines both).

Docker Hosted (port 8082)

For pushing your private images.

  • • Go to Settings → Repositories → Create Repository
  • • Select docker (hosted)
  • • Name: docker-hosted
  • • HTTP port: 8082
  • • Enable Docker V1 API: checked
  • • Blob store: default

Docker Proxy (port 8083)

Caches images from Docker Hub.

  • • Select docker (proxy)
  • • Name: docker-proxy
  • • HTTP port: 8083
  • • Remote storage: https://registry-1.docker.io
  • • Docker Index: Use Docker Hub

Docker Group

Single endpoint for pulling from both.

  • • Select docker (group)
  • • Name: docker-group
  • • HTTP port: 8084
  • • Add members: docker-hosted, docker-proxy

Step 6: Push & Pull Docker Images

# Login to your Nexus Docker registry

docker login your-server-ip:8082

# Tag and push an image

docker tag myapp:latest your-server-ip:8082/myapp:latest docker push your-server-ip:8082/myapp:latest

# Pull from the group (tries hosted first, then proxy)

docker pull your-server-ip:8084/nginx:latest

Important: For HTTP (non-TLS), add your Nexus IP to Docker's insecure registries in /etc/docker/daemon.json:

{
  "insecure-registries": [
    "your-server-ip:8082",
    "your-server-ip:8083",
    "your-server-ip:8084"
  ]
}

Then restart Docker: sudo systemctl restart docker

Step 7: Setup npm Registry (Optional)

Create npm Hosted

  • • Repository type: npm (hosted)
  • • Name: npm-private

Create npm Proxy

  • • Repository type: npm (proxy)
  • • Name: npm-proxy
  • • Remote: https://registry.npmjs.org

# Configure npm to use Nexus

npm config set registry http://your-server-ip:8081/repository/npm-proxy/

Step 8: Reverse Proxy with Nginx (Optional)

# /etc/nginx/sites-available/nexus
server {
    listen 80;
    server_name nexus.yourdomain.com;

    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 $scheme;
        client_max_body_size 1G;
    }
}
sudo ln -s /etc/nginx/sites-available/nexus /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx

Step 9: Firewall Rules

sudo ufw allow 8081/tcp sudo ufw allow 8082/tcp sudo ufw allow 8083/tcp sudo ufw allow 8084/tcp sudo ufw enable sudo ufw status

AWS Security Group: Open inbound TCP on 8081, 8082, 8083, 8084 from your allowed CIDR ranges.

Troubleshooting

Nexus won't start?

Check logs: sudo tail -f /opt/sonatype-work/nexus3/log/nexus.log. Common cause: not enough RAM. Increase JVM heap in /opt/nexus/bin/nexus.vmoptions.

Docker push fails?

Ensure the hosted repo HTTP connector port is set. Check /etc/docker/daemon.json has the insecure registry entry. Restart Docker after changes.

Permission denied?

Verify ownership: sudo chown -R nexus:nexus /opt/nexus /opt/sonatype-work

Summary

  1. Install Java 11
  2. Download and extract Nexus
  3. Create systemd service and start
  4. Login and change admin password
  5. Create Docker hosted, proxy, and group repos
  6. Configure Docker insecure registries
  7. Push and pull images
  8. (Optional) Setup npm/Maven registries
  9. (Optional) Add Nginx reverse proxy with SSL