Nexus Repository Manager Tutorial
Nexus Repository Manager, commonly known as Nexus, is a tool for managing software artifacts and dependencies in a centralized location. Nexus supports a wide range of repository formats, including Maven, npm, PyPI, and Docker, making it a versatile choice for DevOps workflows.
1. Installing Nexus
Option 1: Installing with Docker
To run Nexus using Docker:
docker run -d -p 8081:8081 --name nexus sonatype/nexus3
This will start Nexus on http://localhost:8081.
Option 2: Installing Manually
-
Download Nexus Repository Manager OSS from Sonatype.
-
Extract the downloaded file and navigate to the installation directory.
-
Start Nexus by running:
./nexus run
2. Accessing Nexus
Once Nexus is running, access the web interface at http://localhost:8081.
Default Login Credentials
- Username:
admin - Password: Retrieve the initial password from
nexus-data/admin.password.
3. Configuring Repositories in Nexus
Nexus supports several repository types:
- Hosted Repository: For artifacts created and managed internally.
- Proxy Repository: Proxies and caches artifacts from a remote repository (e.g., Maven Central).
- Group Repository: A virtual repository combining multiple hosted or proxy repositories.
Creating a Hosted Repository
- Go to Repositories in the Nexus dashboard.
- Click Create repository and select the format (e.g., Maven, npm).
- Set the repository details, such as Name, Version Policy, and Deployment Policy.
4. Proxying Remote Repositories
Proxy repositories allow Nexus to cache dependencies from external sources.
Example: Proxying Maven Central
- Go to Repositories and click Create repository.
- Select maven2 (proxy).
- Set Remote storage URL to
https://repo1.maven.org/maven2. - Save the configuration.
5. Setting Up a Group Repository
Group repositories provide a unified access point for multiple repositories.
- Go to Repositories and click Create repository.
- Select maven2 (group) or another format as needed.
- Add multiple repositories to the group (e.g., hosted and proxy repositories).
- Save and use the group repository URL for builds.
6. Uploading Artifacts to Nexus
To upload files or artifacts:
- Navigate to the Browse section in the Nexus dashboard.
- Choose the target repository.
- Click Upload, select your files, and provide required metadata (e.g., groupId, artifactId for Maven artifacts).
Using Maven to Deploy Artifacts
In your pom.xml, add the Nexus repository details:
<distributionManagement>
<repository>
<id>nexus</id>
<url>http://localhost:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
Deploy with:
mvn deploy
7. Configuring Nexus for Docker Images
Nexus can serve as a Docker registry.
-
Go to Repositories and create a docker (hosted) repository.
-
Enable HTTP connector on a custom port (e.g., 8082).
-
To log in and push images to Nexus, configure Docker to use Nexus as a registry:
docker login localhost:8082
docker tag my-image localhost:8082/my-repo/my-image:latest
docker push localhost:8082/my-repo/my-image:latest
8. Setting Up User Roles and Permissions
Nexus allows role-based access control to manage permissions.
- Go to Security > Roles to create custom roles.
- Define permissions such as read, write, or delete for each repository.
- Assign roles to users under Security > Users.
9. Using Nexus with CI/CD Tools
Nexus integrates with CI/CD tools like Jenkins, GitLab, and GitHub Actions.
Example: Integrating Jenkins with Nexus
-
Install the Nexus Artifact Uploader plugin in Jenkins.
-
In your Jenkins pipeline, use the Nexus plugin to upload artifacts:
nexusArtifactUploader artifacts: [[artifactId: 'my-app', file: 'target/my-app.jar']],
credentialsId: 'nexus-credentials',
groupId: 'com.example',
nexusUrl: 'http://localhost:8081',
repository: 'maven-releases'
10. Backing Up Nexus
Regularly back up your Nexus data stored in the nexus-data directory.
- Stop the Nexus service.
- Copy the
nexus-datadirectory to a backup location. - Restart the Nexus service.
Summary
This tutorial covered the basics of Nexus Repository Manager:
- Installing and accessing Nexus.
- Setting up repositories (hosted, proxy, and group).
- Uploading and managing artifacts in Nexus.
- Configuring Nexus as a Docker registry and integrating with CI/CD tools.
Nexus is an essential tool for managing artifacts and dependencies in software development, providing a centralized repository that supports DevOps practices.
Content Review
The content in this repository has been reviewed by chevp. Chevp is dedicated to ensuring that the information provided is accurate, relevant, and up-to-date, helping users to learn and implement programming skills effectively.
About the Reviewer
For more insights and contributions, visit chevp's GitHub profile: chevp's GitHub Profile.