How to Install Nexus Repository Manager on Ubuntu 22.04

Nexus is one of the most popular repository managers in the DevOps world. It allows you to store and retrieve build artifacts and also provides features to push and pull artifacts via CI and IDE integration tools such as Visual Studio and Jenkins.

There are two versions of Nexus repository manager: The commercial version and the open source version. It supports so many formats such PyPi, Docker, Yum, APT, Helm, npm, Go, R, and many more.

Using Nexus as a repository, allows your developers to get and manage packages on the centralized repository manager, which also gives the developers team a single source of truth for every package.

In this tutorial, we will explain how to install the Nexus Repository Manager on a Ubuntu 22.04 server. This tutorial also includes the installation of some packages such as Java OpenJDK and Nginx web server that will be used as a reverse proxy.

Prerequisites

Before you begin, you will need the following requirements:

  • An Ubuntu 22.04 server.
  • A non-root user with sudo/administrator enabled.
  • A domain name pointed to your Ubuntu server IP address (For production).

Installing Java OpenJDK 8

The Nexus Repository Manager required Java OpenJDK and JRE v8. The default Ubuntu repository provides multiple Java versions, So now you will install the Java OpenJDK and JRE v8 from the Ubuntu repository.

Before installing any package, run the apt command below to update and refresh your repositories package index.

sudo apt update

Now, install the Java OpenJDK 8 via the apt command below. Input Y when asked to confirm the installation and press ENTER to proceed.

sudo apt install openjdk-8-jdk

install java

Once Java is installed, verify the Java version on your system using the following command.

java -version

You will see the output in the following screenshot:

check java

Setting up System

To install Nexus, you will need to create a new dedicated Linux user with a valid shell and also need to set up the max open files for both hard and soft limits to '65536'.

Run the following command to create a new dedicated user for the Nexus with the name 'nexus'

sudo useradd -d /opt/nexus -s /bin/bash nexus
sudo passwd nexus

add new user

Next, set the ulimit to '65536' using the below command. This will only affect the system on the current system temporarily. To make it permanent, you can create a new config file that you will do in the next step.

ulimit -n 65536

TO set up ulimit permanently, create a new config file '/etc/security/limits.d/nexus.conf' using nano editor.

sudo nano /etc/security/limits.d/nexus.conf

Add the following configuration to the file. In this example, you are setting up ulimit for specific user 'nexus' with the value '65536'.

nexus - nofile 65536

Save the file and exit the editor when you are finished.

setup ulimit

With all basic requirements in place and configured, you are ready to install the Nexus Repository Manager on your Ubuntu system.

Installing Nexus Repository Manager

The Nexus Repository Manager can be installed via the distribution package that you can download from the official Sonatype download page. At the time of this writing, the latest version of Nexus is v3.41.1. Now, you will download the nexus Repository Manager distribution package and configure the nexus installation.

Download the Nexus Repository Manager package via the wget command as below. If the download process is finished, you will see the file 'nexus-3.41.1-01-unix.tar.gz' on your current working directory.

wget https://download.sonatype.com/nexus/3/nexus-3.41.1-01-unix.tar.gz

Now extract the file 'nexus-3.41.1-01-unix.tar.gz' via the tar command below. And you should get two directories, the 'nexus-3.41.1-01' and 'sonatype-work'.

The directory 'nexus-3.41.1-01' is the main directory for the Nexus package, and the directory 'sonatype-work' is the main working directory for Nexus.

tar xzf nexus-3.41.1-01-unix.tar.gz

Next, move those extracted directories to '/opt' using the following command. The Nexus package directory will be '/opt/nexus' and the Nexus working directory will be '/opt/sonatype-work'.

mv nexus-3.41.1-01 /opt/nexus
mv sonatype-work /opt/

Lastly, change the ownership of both directories to the user and group 'nexus' via the chown command below.

chown -R nexus:nexus /opt/nexus /opt/sonatype-work

download nexus

Next, you will set up your Nexus installation by editing some of the Nexus configuration files.

Open the file '/opt/nexus/bin/nexus.rc' using nano editor.

sudo nano /opt/nexus/bin/nexus.rc

Uncomment the option 'run_as_user' and change the value to 'nexus'. With this configuration, you will be running the Nexus application as the system user 'nexus'.

run_as_user="nexus"

Save the file and exit the editor when you are done.

Next, open the config file '/etc/nexus/bin/nexus.vmoptions' using the nano editor to set up the max heap memory for Nexus.

sudo nano /etc/nexus/bin/nexus.vmoptions

Change the default max memory heap for your Nexus installation in the following options. You can change the size to '1024m' based on the memory that you have on your server.

-Xms1024m
-Xmx1024m
-XX:MaxDirectMemorySize=1024m

Save the file and exit the editor when you are completed.

Now, edit the config file '/opt/sonatype-work/nexus3/etc/nexus.properties' using the nano editor.

sudo nano /opt/sonatype-work/nexus3/etc/nexus.properties

Uncomment the option 'application-host' option and change the value to '127.0.0.1'. This means that you will be running the Nexus on localhost or IP address '127.0.0.1'.

application-host=127.0.0.1

Save the file and exit the editor.

You now have the Nexus Repository Manager downloaded and configured. Next, you will set up a systemd service file for Nexus.

Running Nexus as SystemD Service

On a default installation, the Nexus Repository Manager can be run manually via the binary command 'nexus' that is available on the '/opt/nexus/bin' directory. But, to make it easier for managing Nexus, you will set up a systemd service file for Nexus.

Running Nexus with systemd service file, allows you to manage the nexus process via the systemctl command.

Now, create a new service file '/etc/systemd/system/nexus.service' using nano editor.

sudo /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 when you are done.

Next, run the following command to reload the sytemd manager and apply a new service file for Nexus.

sudo systemctl daemon-reload

Start and enable the 'nexus.service' via the systemctl command below. The Nexus Repository Manager will now start at the local IP address 127.0.0.1 with the default port '8081'. Also, the 'nexus.service' will automatically run at system boot.

sudo systemctl start nexus.service
sudo systemctl enable nexus.service

setup nexus service

Lastly, run the following command to verify the 'nexus.service' and make sure the service is running.

sudo systemctl status nexus.service

check nexus service

With the Nexus running as a systemd service, you can now set up a reverse proxy for Nexus.

Running Nexus with Reverse Proxy

The Nexus Repository Manager is now running on the local IP address '127.0.0.1' with the default port '8081'. To make it accessible from outside of the network, you will use the Nginx reverse proxy that will be running on standard HTTP/HTTPS ports.

Run the following apt command to install the Nginx web server to your Ubuntu system. When prompted to confirm the installation, input Y and press ENTER to proceed.

sudo apt install nginx

install nginx

Once Nginx is installed, run the following systemctl command to check and verify the nginx service. You should see the nginx service is enabled and will be running automatically at system boot. And the status of the nginx service is running.

sudo systemctl is-enabled nginx
sudo systemctl status nginx

check nginx

Next, create a new server block configuration '/etc/nginx/sites-available/nexus' using nano editor.

sudo nano /etc/nginx/sites-available/nexus

Add the following Nginx configuration to the file and be sure to change the domain name.

upstream nexus3 {
  server 127.0.0.1:8081;
}

server {
    listen 80;
    server_name nexus.hwdomain.io;

    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.

Next, run the following command to activate the server block configuration for Nexus by creating a symlink of the config file to the 'sites-enabled' directory. Then, verify the Nginx configuration to make sure Nginx is configured properly.

sudo ln -s /etc/nginx/sites-available/nexus /etc/nginx/sites-enabled/
sudo nginx -t

If your Nginx configuration is configured properly, you should get the output message such as "test is successfull".

Lastly, run the following command to restart the Nginx service and apply the new server block configuration for Nexus.

sudo systemctl restart nginx

You have now set up the Nginx web server as a reverse proxy for Nexus Repository Manager on your Ubuntu machine. You can now access your Nexus installation via your domain name.

setup nginx reverse proxy

Installation of Nexus Repository Manager

At this point, the Nexus Repository manager is running under the Nginx reverse proxy. And it's accessible via the domain name of your installation.

Open the web browser and visit the domain name of your Nexus installation (i.e: http://nexus.hwdomain.io). And you should get the default Nexus page as below.

Click on the "Sign In" button to log in to the Nexus admin dashboard.

nexus login

The default admin password for Nexus is stored at the file '/opt/sonatype-work/nexus3/admin.properties' with the default username admin.

Back to your terminal and run the following command to get the default password for Nexus login. Then, copy the default password for Nexus.

cat /opt/sonatype-work/nexus3/admin.properties

Next, input the user admin and paste the password for Nexus. Then, click "Sign In".

nexus login

Now you will get the setup wizard of Nexus Repository Manager. Click "Next" to proceed.

setup wizards nexus

Input the new strong password for your Nexus installation and repeat. Then, click "Next" again.

change password

For the "Anonymous Access" configuration. Select the option "Disable anonymous access" and click "Next".

disable anonymous acess

Now click "Finish" to complete the Nexus configuration.

setup completes

After the Nexus configuration is completed, you will now see the Nexus administration dashboard. In the below screenshot, you can see the Nexus Repository Manager.

repository manager

Lastly, verify your Nexus installation via the check status button on top. Now make sure all the system status is checked as green, which means Nexus installation and configuration successfully.

system status

Conclusion

In this tutorial, you have set up the Nexus Repository Manager on a Ubuntu 22.04 server. You also have configured the Nginx web server as a reverse proxy for Nexus. You can now add repositories of your projects to the Nexus repository manager and centralize the source of your projects so you can easily build and distribute your applications to developers.

If you are interested to run Nexus on production, you can set up security for your nexus with SSL/TLS via Letsencrypt.

Share this page:

1 Comment(s)