Advanced
Searching inInstall guides
How to search
  • Paste an error message in quotes, e.g. "permission denied", to find the fix table that explains it.
  • Choose an area and a part of the guide (install, first settings, daily use, security, fixes) to go straight to the right step.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

Guide 48Nexus Repository · Git and CI/CD

Install and set up Nexus Repository

Sonatype Nexus Repository is the company's package warehouse: one place for Maven, npm, PyPI, Docker, Helm and more. It caches public packages (faster builds, no outage when the internet or a registry is down, protection against deleted packages) and hosts your own build results. This guide runs Nexus with Docker or the Linux bundle, makes proxy, hosted and group repositories, connects Maven, npm, pip and Docker clients, and covers cleanup, backups and security.

  • 9 Lessons
  • 6 Commands

$ run as a normal user# run as root (or with sudo)

48.1

Know it before you install

Three kinds of repositories. Proxy = a cache of a remote registry (Maven Central, npmjs, PyPI, Docker Hub). Hosted = your own packages (releases, snapshots, private images). Group = one URL that combines several repositories — clients use only the group.

ItemValue
EditionNexus Repository Community Edition (free, with usage limits) or Pro
Imagesonatype/nexus3
Data/nexus-data (volume): database, blob stores, config, logs
First password/nexus-data/admin.password
Port8081/tcp (UI and most formats); Docker repos need their own port or a path behind a proxy
Memorysettings in nexus.vmoptions or INSTALL4J_ADD_VM_PARAMS

What you need: 4 CPU, 8 GB RAM, and a big disk for the blob store (packages grow fast).

48.2

Install with Docker (RHEL and Ubuntu)

docker volume create nexus-data
docker run -d --name nexus --restart unless-stopped -p 127.0.0.1:8081:8081 -p 127.0.0.1:8082:8082 -e INSTALL4J_ADD_VM_PARAMS="-Xms2g -Xmx2g -XX:MaxDirectMemorySize=2g" -v nexus-data:/nexus-data sonatype/nexus3:3.84.0
docker logs -f nexus
… Started Sonatype Nexus COMMUNITY
docker exec nexus cat /nexus-data/admin.password

(Pin the version tag you test. Port 8082 is for a Docker hosted/group repository, below.) Without Docker, download the Linux bundle from Sonatype, unpack it to /opt/nexus, run it as a nexus user with a systemd unit — the steps after this are the same.

48.3

First configuration: the setup wizard

Open http://localhost:8081 (SSH tunnel) and sign in as admin with the password from admin.password. The wizard asks you to:

  1. Set a new admin password (the file is deleted afterwards).
  2. Disable anonymous access — unless you really want public read access.

Then in Settings → Repository → Repositories → Create repository:

RepositoryTypePoints to
maven-centralmaven2 (proxy)https://repo1.maven.org/maven2/ (made by default)
maven-releases, maven-snapshotsmaven2 (hosted)your builds (made by default)
maven-publicmaven2 (group)the three above
npm-proxy → npm-groupnpm proxy + grouphttps://registry.npmjs.org
pypi-proxy → pypi-grouppypi proxy + grouphttps://pypi.org
docker-hubdocker (proxy)https://registry-1.docker.io (with Docker Hub login to avoid limits)
docker-privatedocker (hosted)your images
docker-groupdocker (group), HTTP connector 8082docker-private + docker-hub

Also in Security: add the Docker Bearer Token Realm (for docker login) and npm Bearer Token Realm; create roles and users (or LDAP/SAML); give CI its own user with only deploy rights to the hosted repos.

Put Nexus behind Nginx with HTTPS — docker clients need HTTPS. Route nexus.example.com → 127.0.0.1:8081 and docker.example.com → 127.0.0.1:8082 (with client_max_body_size 0; for big image layers).

48.4

Connect the clients

~/.m2/settings.xml
<settings>
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>https://nexus.example.com/repository/maven-public/</url>
    </mirror>
  </mirrors>
  <servers>
    <server>
      <id>nexus</id>
      <username>ci-deploy</username>
      <password>${env.NEXUS_PASSWORD}</password>
    </server>
  </servers>
</settings>
npm config set registry https://nexus.example.com/repository/npm-group/
pip config set global.index-url https://nexus.example.com/repository/pypi-group/simple
docker login docker.example.com
docker pull docker.example.com/library/nginx:1.27
docker tag shop:1.4.0 docker.example.com/shop:1.4.0
docker push docker.example.com/shop:1.4.0

48.5

Daily use: cleanup, tasks and the real uses

Packages pile up fast. In Settings → Repository → Cleanup Policies make rules (for example: snapshots older than 30 days, proxy components not downloaded for 90 days), attach them to repositories. In System → Tasks schedule:

  • Admin – Cleanup repositories using their associated policies (daily),
  • Admin – Compact blob store (weekly — deleted files really free the disk only after compaction),
  • Docker – Delete unused manifests and images,
  • Admin – Backup of the database (where your edition supports it) — plus a copy of the blob stores.
docker exec nexus du -sh /nexus-data/blobs
curl -s -u admin https://nexus.example.com/service/rest/v1/repositories | jq -r '.[].name'
curl -s -u admin https://nexus.example.com/service/rest/v1/status/check | jq .

Real uses at work:

  • Fast, reliable builds: CI downloads from Nexus on the local network, not from the internet.
  • One place for the company's own artifacts (jars, npm packages, wheels, images, Helm charts).
  • Control: block or audit packages; keep builds working when a public package is deleted.

48.6

Make it safe

Security checklist:

  • Change the admin password; anonymous access off; personal users or SSO.
  • HTTPS only (Nginx); port 8081/8082 only on localhost.
  • Separate CI user with deploy rights only to hosted repos; user tokens instead of passwords.
  • Credentials in CI secrets and ${env…} — never in settings.xml in Git.
  • Cleanup policies + compaction so the disk never fills; monitor disk.
  • Back up the database and blob stores; update Nexus (security fixes).

48.7

Update and remove

docker pull sonatype/nexus3:3.85.0
docker stop nexus && docker rm nexus
docker run -d --name nexus --restart unless-stopped -p 127.0.0.1:8081:8081 -p 127.0.0.1:8082:8082 -v nexus-data:/nexus-data sonatype/nexus3:3.85.0

The data stays in the nexus-data volume. Read the upgrade notes — some versions migrate the database.

48.8

Fix common problems

ProblemCauseFix
admin.password file is missingThe password was already changed in the wizard.Use the new password; otherwise follow Sonatype's admin reset steps.
docker login fails: http: server gave HTTP response to HTTPS clientDocker needs HTTPS.Put the Docker connector behind Nginx with TLS.
docker login 401Docker Bearer Token Realm not active, or no rights.Add the realm in Security → Realms; check the user role.
Disk fullNo cleanup or no compaction.Cleanup policies + the Compact blob store task.
Nexus slow or OutOfMemoryErrorHeap or direct memory too small.Raise -Xmx and -XX:MaxDirectMemorySize (and the host RAM).
Maven still downloads from the internetThe mirror is not used.<mirrorOf>*</mirrorOf> in settings.xml; mvn help:effective-settings.
Proxy repo returns 404 for a public packageWrong remote URL or no outbound internet.Check the remote URL; test from the Nexus host with curl.

48.9

Next steps

1What is the difference between a proxy, a hosted and a group repository?

Proxy caches a public registry, hosted stores your own packages, group combines them behind one URL.

2You deleted many old components but the disk is still full. Why?

The space is freed only after the Compact blob store task runs.

All commands in this chapter