Introduction to Nexus
Nexus is a Maven repository manager used for storing, distributing, and managing software packages and libraries. Developed by Sonatype, it is an open-source project that offers both community and professional editions.
Nexus supports various types of Maven repositories, including Maven2, Maven3, npm, and Docker, and provides a range of features such as security, license management, user management, and customizable workflows. With Nexus, users can manage and distribute software more efficiently while saving storage space and bandwidth.
The main features of Nexus include:
- Unified Repository Management: Nexus allows you to manage multiple repositories through a single interface, organizing them into logical repositories.
- Security Policies: You can enforce strict access control on repositories and groups, allowing only authorized users to access certain content.
- Hosting Libraries: Nexus can host your packages, dependencies, and other binaries, providing secure HTTPS upload and download options.
- Automation: You can automate processes such as publishing to the Maven Central Repository, auditing, and version control, enhancing release efficiency and quality.
In summary, Nexus is a powerful Maven repository manager that helps users manage and distribute software packages and libraries while improving software release quality and efficiency.
Here are a few methods for installing and deploying Nexus:
Installing and Deploying Using Docker Image
Docker Image Download Link: Nexus Docker Hub. The Docker image is only available for version 3.x; if you need version 2.x, please refer to the system installation methods below.
To install Nexus in Docker, follow these steps:
-
Pull the Nexus Docker Image
Execute the following command to pull the Nexus Docker image:
1
docker pull sonatype/nexus3
-
Create and Start the Nexus Container
Use the following command to create and start the Nexus container:
1
docker run -d -p 8081:8081 --name nexus sonatype/nexus3
This command creates and starts a container named
nexus
, mapping the Nexus service in the container to port 8081 on the host. -
Access the Nexus Web Interface
Enter
http://<host>:8081
in your browser, where<host>
is the IP or domain name of the Docker host. Upon your first visit, you will be prompted to set up the username and password for the admin account. Once set, you can access the Nexus Web interface. -
Configure Nexus
In the Nexus Web interface, you can perform various configurations, such as creating Maven repositories, uploading and downloading software packages, etc. For specific procedures, please refer to the official Nexus documentation.
-
Data Persistence
By default, data for Docker containers is stored internally, and this data will be lost when the container is deleted or recreated. To preserve data in Nexus, you need to mount the data directory to the host.
You can create a data volume with the following command and then mount it to the
/nexus-data
directory in the Nexus container:1
mkdir /some/dir/nexus-data && chown -R 200 /some/dir/nexus-data
1
docker run -d -p 8081:8081 --name nexus -v /some/dir/nexus-data:/nexus-data sonatype/nexus3
This will create a data volume named
nexus-data
and mount it to the/nexus-data
directory in the Nexus container, ensuring that data is retained even when the Nexus container is deleted or recreated.
Viewing Logs
To view the logs:
|
|
Output (indicating successful startup):
|
|
Viewing the Password
To view the admin password:
|
|
Accessing the Container
To enter into the container:
|
|
Stopping the Container
Make sure to stop the database gracefully, allowing for additional closing time:
|
|
In summary, installing Nexus using Docker involves pulling the Nexus image, creating and starting the Nexus container, accessing the Nexus Web interface, configuring Nexus, and ensuring data persistence.
Direct Installation on Linux Systems
-
Download Nexus
Download the latest version of Nexus from the official website: Nexus Downloads.
Choose the appropriate archive for your system. If you are using Linux, you can download it using the following command:
1
wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
-
Extract Nexus
Unpack the downloaded Nexus archive to the desired installation directory. If you are on Linux, you can use the following command:
1
tar -zxvf latest-unix.tar.gz
-
Configure Nexus
Navigate to the extracted Nexus directory and edit the
bin/nexus.rc
file.Modify the following parameters in the file:
run_as_user
: Specify the user that runs Nexus; the default isroot
.nexus_home
: Specify the installation path for Nexus.
-
Start Nexus
Execute the following command to start Nexus:
1
./bin/nexus start
This command will start Nexus and run it as a background process. You can stop Nexus using the following command:
1
./bin/nexus stop
-
Access Nexus
Enter
http://<nexus_host>:8081
in your browser, where<nexus_host>
is the IP or domain name of the Nexus host.Upon your first visit, you will be prompted to set up the username and password for the admin account. Once done, you can access the Nexus management console.
In conclusion, installing Nexus involves downloading the archive, extracting it to a specified directory, editing the nexus.rc
configuration file, and then starting Nexus from the command line. Once installed, you can access the Nexus management console through your browser for configuration and use.
For information on backing up and restoring Nexus, please refer to this link: Backup and Restore Nexus