Nexus Repository Manager is a widely-used repository manager in the DevOps community. It offers a centralized platform for storing and retrieving build artifacts, as well as seamless integration with CI and IDE tools like Visual Studio and Jenkins. This tutorial will guide you through the installation process of Nexus Repository Manager on an Ubuntu 22.04 server, including the setup of Java OpenJDK, Nginx web server, and a reverse proxy.
Prerequisites
Before you begin the installation, make sure you have the following requirements in place:
- An Ubuntu 22.04 server.
- A non-root user with sudo/administrator privileges.
- A domain name pointed to your Ubuntu server IP address (for production purposes).
Installing Java OpenJDK 8
Nexus Repository Manager requires Java OpenJDK and JRE v8. To install Java OpenJDK, follow these steps:
- Update and refresh the package index of your repositories by running the following command:
sudo apt update
- Install Java OpenJDK 8 using the following command. When prompted, type ‘Y’ to confirm the installation:
sudo apt install openjdk-8-jdk
- Verify the Java version on your system by running the following command:
java-version
You should see the installed Java version displayed in the output.
Setting up the System
To prepare your system for Nexus installation, you need to create a new dedicated Linux user and set up the maximum open files limit. Follow these steps:
- Create a new dedicated user for Nexus named ‘nexus’ with the following command:
sudo useradd -d /opt/nexus -s /bin/bash nexus
- Set a password for the ‘nexus’ user by running the following command and following the prompts:
sudo passwd nexus
- Temporarily set the maximum open files limit to ‘65536’ by executing the following command:
ulimit -n 65536
Note: To make this change permanent, you will create a new configuration file in the next step.
- Create a new configuration file ‘nexus.conf’ for the ‘nexus’ user’s ulimit settings using the nano editor:
sudo nano /etc/security/limits.d/nexus.conf
- Add the following configuration to the file, replacing ‘username’ with ‘nexus’ and ‘value’ with ‘65536’:
nexus - nofile 65536
- Save the file and exit the editor.
With these basic system requirements in place, you are now ready to install Nexus Repository Manager.
Installing Nexus Repository Manager
Nexus Repository Manager can be installed from the official Sonatype download page. Follow these steps to download and configure Nexus:
- Download the Nexus Repository Manager package using the wget command:
wget https://download.sonatype.com/nexus/3/nexus-3.41.1-01-unix.tar.gz
- Extract the downloaded package using the tar command:
tar xzf nexus-3.41.1-01-unix.tar.gz
- Move the extracted directories to ‘/opt’ with the following commands:
mv nexus-3.41.1-01 /opt/nexus mv sonatype-work /opt/sonatype-work
- Change the ownership of both directories to the ‘nexus’ user:
chown -R nexus:nexus /opt/nexus /opt/sonatype-work
- Open the ‘/opt/nexus/bin/nexus.rc’ file using the nano editor:
sudo nano /opt/nexus/bin/nexus.rc
- Uncomment the ‘runasuser’ option and set its value to ‘nexus’:
run_as_user="nexus"
- Save the file and exit the editor.
Next, open the ‘/etc/nexus/bin/nexus.vmoptions’ file to configure the maximum heap memory for Nexus:
sudo nano /etc/nexus/bin/nexus.vmoptions
- Modify the following options to set the heap memory size to ‘1024m’:
-Xms1024m -Xmx1024m -XX:MaxDirectMemorySize=1024m
- Save the file and exit the editor.
Now, edit the ‘/opt/sonatype-work/nexus3/etc/nexus.properties’ file:
sudo nano /opt/sonatype-work/nexus3/etc/nexus.properties
- Uncomment the ‘application-host’ option and set its value to ‘127.0.0.1’:
application-host=127.0.0.1
- Save the file and exit the editor.
The Nexus Repository Manager is now downloaded and configured. To run Nexus as a systemd service, follow the next section.
Running Nexus as a SystemD Service
Instead of manually running Nexus, you can configure it as a systemd service for easier management. Follow these steps:
- Create a new service file for Nexus using the nano editor:
sudo nano /etc/systemd/system/nexus.service
- Add the following configuration to the file:
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target
- Save the file and exit the editor.
Reload the systemd manager and apply the new service file for Nexus by running the following command:
sudo systemctl daemon-reload
Start and enable the ‘nexus.service’ using the systemctl command:
sudo systemctl start nexus.service sudo systemctl enable nexus.service
Finally, verify the status of the ‘nexus.service’ to ensure it is running without any issues:
sudo systemctl status nexus.service
With Nexus running as a systemd service, you can now set up a reverse proxy to make it accessible from outside your network.
Running Nexus with Reverse Proxy
To enable external access to Nexus, you can utilize Nginx as a reverse proxy. Follow these steps to set it up:
- Install the Nginx web server on your Ubuntu system using the following command:
sudo apt install nginx
- Verify the status of the Nginx service to ensure it is enabled and running:
sudo systemctl is-enabled nginx
sudo systemctl status nginx
- Create a new server block configuration for Nexus using the nano editor:
sudo nano /etc/nginx/sites-available/nexus
- Add the following Nginx configuration to the file, replacing ‘domain_name’ with your domain name:
upstream nexus3 { server 127.0.0.1:8081; } server { listen 80; server_name domain_name; location / { proxy_pass http://nexus3/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; proxy_set_header X-Forward-Proto http; proxy_set_header X-Nginx-Proxy true; proxy_redirect off; } }
- Save the file and exit the editor.
Activate the server block configuration for Nexus by creating a symlink in the ‘sites-enabled’ directory and verify the Nginx configuration:
sudo ln -s /etc/nginx/sites-available/nexus /etc/nginx/sites-enabled/ sudo nginx -t
If the configuration is correct, you should see a message indicating a successful test.
Restart the Nginx service to apply the new server block configuration for Nexus:
sudo systemctl restart nginx
Congratulations! You have now set up Nginx as a reverse proxy for Nexus Repository Manager. You can access your Nexus installation using your domain name.
Installation of Nexus Repository Manager
With Nexus running under the Nginx reverse proxy, you can now access it through your domain name. Follow these steps to complete the installation:
- Open a web browser and visit your Nexus installation’s domain name (e.g., http://nexus.example.io).
- You should see the default Nexus page.
- Click on the “Sign In” button to access the Nexus admin dashboard.
- The default admin password for Nexus is stored in the ‘/opt/sonatype-work/nexus3/admin.properties’ file.
- Retrieve the default password by running the following command:
cat /opt/sonatype-work/nexus3/admin.properties
- Enter the username ‘admin’ and paste the password to sign in to the Nexus admin dashboard.
- You will be presented with the setup wizard for Nexus Repository Manager.
- Follow the wizard instructions, setting a new strong password for your Nexus installation.
- In the “Anonymous Access” configuration, select the option to disable anonymous access.
- Click “Finish” to complete the Nexus configuration.
- You will now see the Nexus administration dashboard.
- Verify your Nexus installation by clicking the check status button on top. Ensure all system status checks are green, indicating a successful installation and configuration.
Congratulations! You have successfully installed Nexus Repository Manager on your Ubuntu 22.04 server. You can now add repositories for your projects and benefit from centralized package management and distribution.
In conclusion, Nexus Repository Manager provides a powerful solution for managing build artifacts and streamlining the development process. With its seamless integration with CI and IDE tools, you can enhance collaboration and achieve faster, more efficient software delivery. By following this tutorial, you have gained the knowledge to set up Nexus on your Ubuntu server, ensuring a reliable and scalable environment for your development needs.
For professional and reliable cloud hosting solutions, consider Shape.host’s Linux SSD VPS services. Shape.host offers secure, scalable, and high-performance VPS hosting tailored to meet your specific requirements. Visit Shape.host for more information and to explore their hosting solutions.