LinuxTutorialsUbuntu

How To Install Nexus Repository on Ubuntu 20.04 LTS

Install Nexus Repository on Ubuntu 20.04

In this tutorial, we will show you how to install Nexus Repository on Ubuntu 20.04 LTS. For those of you who didn’t know, Nexus Repository is an open-source repository that supports many artifact formats, including Docker, Java, Docker, Conan components, and more. It allows you to collect, and manage your dependencies and makes it easier to distribute your software. It is a single source of all components, binaries, and build artifacts.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Nexus Repository on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 20.04, 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Nexus Repository on Ubuntu 20.04 LTS Focal Fossa

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade

Step 2. Installing Java.

Nexus repository manager requires Java Runtime Environment. Run the following command to install Java to your system:

sudo apt install openjdk-8-jre-headless

Once Java is installed, you can verify the installed version of Java with the following command:

java -version

Step 3. Create a User Account for Nexus.

Now create a separate user to run Nexus:

useradd -M -d /opt/nexus -s /bin/bash -r nexus
echo "nexus ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/nexus

Step 4. Installing Nexus Repository on Ubuntu 20.04.

Now we download the latest Nexus Repository Manager Setup from the official page:

sudo wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
tar -zxvf latest-unix.tar.gz

Then, rename the extracted Nexus setup folder to Nexus:

sudo mv /opt/nexus-3.30.1-01 /opt/nexus

Next, give permission to nexus files and nexus directory to Nexus user:

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

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

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

Add the following line:

run_as_user="nexus"

After that, edit the nexus.vmoptions configuration file and define max memory size:

nano /opt/nexus/bin/nexus.vmoptions

Add the following line:

-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

Step 5. Create a Systemd Service File for Nexus.

Now we create a systemd service file to manage the Nexus service:

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

Add the following lines:

[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 and close the file then start the Nexus service and enable it to start at system reboot:

sudo systemctl daemon-reload
sudo systemctl start nexus
sudo systemctl enable nexus

Step 6. Accessing Nexus Repository Web Interface.

Once successfully installed, open your web browser and access the Nexus web UI using the URL http://your-server-ip-address:8081/. You will be redirected to the following page:

Install Nexus Repository on Ubuntu 20.04 LTS Focal Fossa

Click the sign-in button at the top right corner. Login as admin. The password is located on the file, /opt/nexus/sonatype-work/nexus3/admin.password. To get the password, just print the contents of the file:

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

Congratulations! You have successfully installed Nexus Repository. Thanks for using this tutorial for installing the Nexus Repository on Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you check the official Nexus Repository website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button