- Priya
- December 11, 2021
Steps to Setup Nexus Repository Manager on Ubuntu 20.04 LTS
Nexus is a free & open source repository manager. It helps to collect & manage the dependencies so that we are not constantly juggling a collection of JARs. It provides a simple way to create & distribute software. It is used to collect, retrieve, manage our artifacts. Artifacts is a place where we can store all artifacts which are needed for the projects.
There are some steps to setup Nexus repository manager on ubuntu:
Prerequisites:
- Open JDK 8
- Minimum CPU’s: 4
- ubuntu server with sudo privileges.
- Firewall/Inbound port: 22, 8081
Step 1: Update the System.
apt-get update
Step 2: Install java.
apt install openjdk-8-jdk
- Check Java version.
java -version
- Here is the command output.
root@ip-172-31-19-239:/home/ubuntu# java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~20.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
Step 3: To create a system account for Nexus.
useradd -M -d /opt/nexus -s /bin/bash -r nexus
- Provide the sudo permission to Nexus user.
echo "nexus ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/nexus
Step 4: Download the Nexus.
- Change the directory.
cd /opt
- Run the following command to download the nexus.
wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
- Here is the command output.
root@ip-172-31-19-239:/home/ubuntu# cd /opt
root@ip-172-31-19-239:/opt# wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
--2021-12-08 06:36:09-- https://download.sonatype.com/nexus/3/latest-unix.tar.gz
Resolving download.sonatype.com (download.sonatype.com)... 52.9.57.40, 54.176.205.63
Connecting to download.sonatype.com (download.sonatype.com)|52.9.57.40|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.37.0-01-unix.tar.gz [following]
--2021-12-08 06:36:10-- https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.37.0-01-unix.tar.gz
Resolving sonatype-download.global.ssl.fastly.net (sonatype-download.global.ssl.fastly.net)... 199.232.113.194
Connecting to sonatype-download.global.ssl.fastly.net (sonatype-download.global.ssl.fastly.net)|199.232.113.194|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 211451295 (202M) [application/x-gzip]
Saving to: ‘latest-unix.tar.gz’
latest-unix.tar.gz 100%[=============================================================>] 201.66M 91.2MB/s in 2.2s
2021-12-08 06:36:12 (91.2 MB/s) - ‘latest-unix.tar.gz’ saved [211451295/211451295]
- Extract the downloaded folder.
tar -zxvf latest-unix.tar.gz
- Here is the command output.
root@ip-172-31-19-239:/opt# tar -zxvf latest-unix.tar.gz
nexus-3.37.0-01/.install4j/9d17dc87.lprop
nexus-3.37.0-01/.install4j/MessagesDefault
nexus-3.37.0-01/.install4j/build.uuid
nexus-3.37.0-01/.install4j/e4ada6b7.lprop
nexus-3.37.0-01/.install4j/i4j_extf_0_17is1ik.utf8
nexus-3.37.0-01/.install4j/i4j_extf_10_17is1ik_10358jn.png
nexus-3.37.0-01/.install4j/i4j_extf_11_17is1ik_1gne9sv.png
nexus-3.37.0-01/.install4j/i4j_extf_12_17is1ik_sc8j43.png
nexus-3.37.0-01/.install4j/i4j_extf_13_17is1ik_10nxrsm.png
nexus-3.37.0-01/.install4j/i4j_extf_14_17is1ik_yd7am4.png
nexus-3.37.0-01/.install4j/i4j_extf_15_17is1ik_vu6hgs.png
nexus-3.37.0-01/.install4j/i4j_extf_16_17is1ik_1g1wykh.png
nexus-3.37.0-01/.install4j/i4j_extf_17_17is1ik_18gg8kx.png
- To rename the extracted Nexus setup folder to nexus.
mv /opt/nexus-3.37.0-01 /opt/nexus
- Provide the following permission to Nexus & sonatype-work folder.
chown -R nexus:nexus /opt/nexus
chown -R nexus:nexus /opt/sonatype-work
- Run nexus as service at boot time.
vim /opt/nexus/bin/nexus.rc
- Uncomment & edit the following line.
run_as_user="nexus"
- To change the nexus JVM heap size.
- Open the file.
vim /opt/nexus/bin/nexus.vmoptions
- Edit the following lines:
-Xms1024m
-Xmx1024m
-XX:MaxDirectMemorySize=1024m
-XX:LogFile=./sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
Step 5: To run nexus as service using Systemd.
vim /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
- To start & enable nexus servic.
systemctl start nexus
systemctl enable nexus
- Check nexus service status.
systemctl status nexus
- Here is the command output.
root@ip-172-31-19-239:/opt# systemctl start nexus
root@ip-172-31-19-239:/opt# systemctl enable nexus
Created symlink /etc/systemd/system/multi-user.target.wants/nexus.service → /etc/systemd/system/nexus.service.
root@ip-172-31-19-239:/opt# systemctl status nexus
● nexus.service - nexus service
Loaded: loaded (/etc/systemd/system/nexus.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-12-08 06:40:24 UTC; 8s ago
Main PID: 17464 (java)
Tasks: 41 (limit: 4700)
Memory: 568.3M
CGroup: /system.slice/nexus.service
└─17464 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -server
- To check nexus logs.
tail -f /opt/sonatype-work/nexus3/log/nexus.log
- Here is the command output.
root@ip-172-31-19-239:/opt# tail -f /opt/sonatype-work/nexus3/log/nexus.log
2021-12-08 06:40:34,795+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.extender.NexusBundleTracker - ACTIVATED org.sonatype.nexus.rapture [3.37.0.01]
2021-12-08 06:40:34,795+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.extender.NexusBundleTracker - ACTIVATING org.sonatype.nexus.quartz [3.37.0.01]
2021-12-08 06:40:34,846+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.extender.NexusBundleTracker - ACTIVATED org.sonatype.nexus.quartz [3.37.0.01]
2021-12-08 06:40:34,846+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.extender.NexusBundleTracker - ACTIVATING org.sonatype.nexus.oss-edition [3.37.0.01]
2021-12-08 06:40:34,857+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.extender.NexusBundleTracker - ACTIVATED org.sonatype.nexus.oss-edition [3.37.0.01]
2021-12-08 06:40:34,858+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.extender.NexusContextListener - Running lifecycle phases [KERNEL, STORAGE, RESTORE, UPGRADE, SCHEMAS, EVENTS, SECURITY, SERVICES, CAPABILITIES, TASKS]
2021-12-08 06:40:34,859+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.extender.NexusLifecycleManager - Start KERNEL
2021-12-08 06:40:34,861+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.internal.log.LogbackLoggerOverrides - File: /opt/sonatype-work/nexus3/etc/logback/logback-overrides.xml
- To open the 8081 port number in UFW firewall.
ufw allow 8081/tcp
- Here is the command output.
root@ip-172-31-19-239:/opt# ufw allow 8081/tcp
Rules updated
Rules updated (v6)
Step 6: Open Nexus Repository Web Interface.
http://server-ip:8081
- Here is the command output.
- To click on Sign in option.
- Default username is : admin
- Run the below command for finding the default password.
cat sonatype-work/nexus3/admin.password
- Here is the command output.
root@ip-172-31-19-239:/opt# cat sonatype-work/nexus3/admin.password
1ad9ae73-4bd3-4619-bd90-46cec26638f3
- Click on Next.
- To change the default password.
- Click Next.
- To configure Anonymous Access.
- Click on Finish.
- Finally,Log into Nexus Repository Manager.