In today's article, I will talk about how to install Nexus repository manager on Ubuntu. Nexus, helps you to to collect, retrieve, manage our artifacts. Let's get started.

Install Java

First, we need to install Java. If you already have Java installed, you can skip this step. You can install Java by running the following command:

1
sudo apt install openjdk-8-jre-headles

You can check the Java version by running the following command:

1
java -version

Now we have finished installing Java. Let’s move on to the next step. In next step, we will download Nexus repository manager.

Download Nexus

Before downloading the Nexus, we need to `cd` in to `opt` directory. You can do that by running the following command:

1
cd /opt

Now we can download Nexus by running the following command:

1
sudo wget https://download.sonatype.com/nexus/3/nexus-3.43.0-01-unix.tar.gz

Now we have downloaded Nexus. Let’s move on to the next step. In next step, we will extract the Nexus.

Extract Nexus

Now we can extract the Nexus by running the following command:

1
sudo tar -xvzf nexus-3.43.0-01-unix.tar.gz

Rename the extracted Nexus setup folder to nexus by running the following command:

1
sudo mv /opt/nexus-3.43.0-01 /opt/nexus

Now we have extracted the Nexus. Let’s move on to the next step. In next step, we will create a user and group for Nexus.

Create an user for Nexus

As a better security practice, we don't run nexus service using root user, so lets create new user named `nexus` to run nexus service by running the following command:

1
sudo adduser nexus

Now we have created a user for Nexus. Let’s set no password for nexus user open the visudo file in ubuntu by running the following command:

1
sudo visudo

Add the following line to the end of the file:

1
nexus ALL=(ALL) NOPASSWD: ALL

Now we have set no password for nexus user. Let’s move on to the next step. In next step, we will give pernission for nexus user.

Give permission for nexus user

Now we can give permission for nexus user by running the following command:

1
2
3
sudo chown -R nexus:nexus /opt/nexus

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

To run nexus as service at boot time, open /opt/nexus/bin/nexus.rc file, uncomment it and add nexus user as shown below:

1
sudo vim /opt/nexus/bin/nexus.rc
1
run_as_user="nexus"

Next we nedd to Increase the nexus JVM heap size, open the /opt/nexus/bin/nexus.vmoptions file, you can modify the size as shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
-Xms1024m
-Xmx1024m
-XX:MaxDirectMemorySize=1024m

-XX:LogFile=./sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=/etc/karaf/java.util.logging.properties
-Dkaraf.data=./sonatype-work/nexus3
-Dkaraf.log=./sonatype-work/nexus3/log
-Djava.io.tmpdir=./sonatype-work/nexus3/tmp

Now we have given permission for nexus user. Let’s move on to the next step. In next step, we will create a service for Nexus.

Create a service for Nexus

To run nexus as service using Systemd, create a file named `nexus.service` in `/etc/systemd/system` directory by running the following command:

1
sudo vim /etc/systemd/system/nexus.service

Add the following content to the file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[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

To start nexus service using systemctl

1
sudo systemctl start nexus

To enable nexus service to start at boot time

1
sudo systemctl enable nexus

To check nexus service status

1
sudo systemctl status nexus

Now we have created a service for Nexus. Let’s move on to the next step. In next step, we will access Nexus.

Access Nexus

If you are running UFW firewall on Ubuntu, open the firewall port 8081 using below command

1
sudo ufw allow 8081

Now we can access Nexus by visiting http://<server_IP:8081>:8081 in our browser. You can login to Nexus using the default username and password. The default username is admin and the default password is admin123. You can change the default password by clicking on the Change password link.

Conclusion

In this tutorial, we have learned how to install Nexus repository on Ubuntu. If you have any issue regarding this tutorial, mention your issue in the comment section or reach me through my E-mail.

Happy Coding