Install Sonatype Nexus on Ubuntu

Install Nexus Repository on Ubuntu Step by Step Guide

Introduction

Nexus Repository Manager is a powerful tool for managing software artifacts, including Java-based components, Docker containers, and more. It provides a centralized location for storing, sharing, and distributing these artifacts, making it easy for developers and DevOps teams to collaborate and streamline their workflows.

Artifacts in DevOps : In Devops, When we build project we export software build files which may consist of the project source code, dependencies, binaries or resources, and could be represented in different layout depending on the technology. Using CI/CD build tools we bind all the project source code and export single file like WAR, Jar or NuGet etc. which is known as artifact. These artifacts further used in deployment phase we deploy these artifacts on our production / pre-production server.

In this blog post, We will walk through the steps for installing Nexus Repository Manager on Ubuntu.

Prerequisites

  1. Pre Installed OpenJDK-8
  2. Minimum 4 CPU’s Required
  3. Ubuntu Server with User sudo Privileges.
  4. Any Web Browser
  5. Firewall/Inbound port: 22, 8081

Step 1: Upgrade your system to latest version

Before you begin the installation process, it’s a good idea to update your system’s package list and upgrade any existing packages to their latest versions. Open a terminal and run the following commands :

sudo apt update
sudo apt upgrade -y

Once the system upgrade process completed, We will check whether Java is already installed in the system.

Step 2: Verify if Java already installed in the system

To check Java, Run the following commands :

java -version

If Java is already installed, You will get below like output with Java version details :

Else if Java is not installed in your system you will get below like output :

If you need help with JDK installation, Read How to Install JDK on Ubuntu

Note : To install Nexus Repository successfully, We recommend to install OpenJDK – 8.

I am assuming you have JDK installed, Now we will proceed with the Nexus installation.

Step 3: Download Nexus Repository package on Ubuntu

  • Change directory and Navigate to /opt directory
cd /opt
  • Download Nexus Repository package on Ubuntu using wget
sudo wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz

This code will download latest Nexus 3 package and the Output may be as shown below :

Step 4: Configure Nexus Repository on Ubuntu

  • Extract the Nexus repository setup in /opt directory using following command :
sudo tar -zxvf latest-unix.tar.gz

Once you extract the Nexus zip file, You may see the output as below. Now we need to move the all content from extracted folder to nexus folder.

install nexus in ubuntu linux 2024
  • Replace the nexus-3.52.0-01 from latest nexus version which can be seen in output window. Now rename the extracted Nexus setup folder to nexus.

In this case it will be nexus-3.68.1-02.

sudo mv /opt/nexus-3.52.0-01 /opt/nexus

Here replace nexus-3.52.0-01 with your version.

Let’s add a User specially to run Nexus Service because It is not recommended to run nexus service using root user.

We will create user named as nexus and set password for the user as per your choice.

sudo adduser nexus

Press Enter twice if asked, You may see output as below

To set no password for nexus user, Open the visudo file in ubuntu

sudo nano visudo

Add below line into it, save and exit. To save changes in nano editor press CTRL + X and then Enter.

nexus ALL=(ALL) NOPASSWD: ALL

Give read/write permission to nexus files and nexus directory to nexus user using following code

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

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

Uncomment below line or directly add in the file.

run_as_user="nexus"

We will increase the nexus JVM heap size to work nexus service smoothly. To change the size open nexus.vmoptions file using following code :

sudo nano /opt/nexus/bin/nexus.vmoptions

Note : If size is already same or bigger as below configuration, Skip this step

Now copy and paste below configuration in nexus.vmoptions file

-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

To run Nexus as a service using systemd open nexus.service file by following code :

sudo nano /etc/systemd/system/nexus.service

Now copy and paste below line in nexus.service 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

Note : Here nexus is the user.

Save and exit the file using CTRL + X and then Enter.

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

sudo ufw allow 8081/tcp

Step 5: Start Nexus Service

Initialize the systemctl service

sudo systemctl daemon-reload

Start Nexus Service using systemctl run following command

sudo systemctl start nexus

Enable Nexus Service at system startup, Run following command :

sudo systemctl enable nexus

To check Nexus Service status run following command :

sudo systemctl status nexus

You may see output like below :

If nexus service is not started, You can check the nexus logs using below command :

sudo tail -f /opt/sonatype-work/nexus3/log/nexus.log

Note : If you are installing Nexus on Linux VM on any cloud then You need to enable port 8081 in networking inbound port rule.

Step 6: Access Nexus Repository Web Interface

To access Nexus repository web interface , Open your favorite browser

Now To access Nexus repository web interface use following URL syntax :

http://server_IP:8081

Here replace server_IP with your server IP or If you are using on local machine, Open below URL :

http://localhost:8081

Now you will be able to see Nexus web interface in your browser as below :

It will ask for Username and Password, Default Username is admin and to retrieve default password copy above highlighted path and run using below command :

sudo cat /opt/nexus/sonatype-work/nexus3/admin.password

You will be see the default password, Copy the default nexus password and paste in the password field and click on Sign-in button, You can reset the password once logged in to nexus.

Now you may see the next screen as below :

Click on Next button and you may see the next screen as below :

Now you can set your own password for further use, Keep a note of your Password and default username will be admin

After entering your Password click on Next and you may see the next screen as below :

Now we will continue with the default selection as Enable anonymous access and click on Next button and you may see next screen as below :

Now it will show the final page where It’s saying Installation is completed, Now click on Finish button and you will see final dashboard of Nexus service as shown below :

Woohoo !!.. We have successfully installed and configured Nexus Service.

Conclusion

Congratulations! You have successfully installed and configured Nexus Repository Manager on your Ubuntu server. You can now use it to manage your software artifacts and streamline your development and DevOps workflows.

If you face any difficulty or error while following above steps, Please write in comment section.

19 Comments

  1. David James

    Thanks for the help, This blog is explaining in detail with every steps. Thanks again

  2. Blare Doss

    Your ability to distill complexity into actionable knowledge is unparalleled. Thank you for this gem!

  3. Assay Dolf

    I appreciate how well-researched and thorough this article is. It’s a benchmark for quality content!

  4. Victoria

    You’ve turned a daunting subject into something approachable and even fun to learn!

  5. victoria

    I was facing error while following other website post but now i have done it successfully with the help of this blog. thanks

  6. zerhusenas

    Detailed Explanation. Thanks

  7. Holly

    Outstanding, My all errors resolved.

  8. Ramo Slee

    The attention to detail in this blog is truly commendable. Thank you for sharing your expertise!

  9. Melvica Wring

    I look forward to more articles from you. Your work is a true asset to the community!

  10. Travis

    This blog is a testament to the power of sharing knowledge. You’re empowering others!

  11. Brandy Rolw

    I’m definitely sharing this with my team. They’ll find it as valuable as I did!

  12. Derik Roofe

    This blog feels like a mentor guiding me through the blog. Immensely grateful!

  13. Allen Rodre

    Your work is making a real difference in the community. Thank you for sharing your knowledge!

  14. Moris Blode

    I can’t thank you enough for this. It’s rare to find content that’s both in-depth and accessible.

  15. Rodrig Zoph

    Your blog has saved me hours of research. I truly appreciate the effort!

  16. Frieden Spfe

    This article is a testament to your expertise. Every detail is meticulously covered!

Leave a Reply

Your email address will not be published. Required fields are marked *