# SonaType Nexus Installation  on Ubuntu

1. **Update Package List:**
    
    Open a terminal and ensure your package list is up to date by running:
    
    ```bash
    sudo apt update
    ```
    
2. **Install Prerequisites:**
    
    <div data-node-type="callout">
    <div data-node-type="callout-emoji">💡</div>
    <div data-node-type="callout-text">Installing Java on the root gives access to all the users who want to use Java or JRE</div>
    </div>
    
    <div data-node-type="callout">
    <div data-node-type="callout-emoji">💡</div>
    <div data-node-type="callout-text">Perform the Entire Installation in Root, Anyway, we are going to the application a separate access with a new user</div>
    </div>
    
    Installation of the OpenJDK which is a required pre-requisites for Nexus:
    
    ```bash
    sudo apt-get install openjdk-17-jdk -y
    ```
    
    and actually, it depends on the Java JRE Version 8 as per the official documentation
    
    So, we are going to install that as well, So, let's start with getting the OpenJDK from the [OpenLogic](https://www.openlogic.com/openjdk-downloads?field_java_parent_version_target_id=416&field_operating_system_target_id=426&field_architecture_target_id=391&field_java_package_target_id=396) official website
    
    ```bash
    wget https://builds.openlogic.com/downloadJDK/openlogic-openjdk/8u382-b05/openlogic-openjdk-8u382-b05-linux-x64-deb.deb
    ```
    
    Now before installing the OpenJDK, we need to first install the font dependency of it and then we are going to install the OpenJDK as shown below:
    
    ```bash
    sudo apt install fonts-dejavu 
    sudo dpkg -i openlogic-openjdk-8u382-b05-linux-x64-deb.deb
    ```
    
3. <div data-node-type="callout">
    <div data-node-type="callout-emoji">💡</div>
    <div data-node-type="callout-text"><strong>Specific Purpose</strong>: This method is suitable for creating system users dedicated to running services, where interactive login is not required, and a specific shell and home directory are not necessary.</div>
    </div>
    

```shell
sudo useradd \
    --system \
    --no-create-home \
    --shell /bin/false nexus
```

Let's check the Nexus latest version from the [SonaType Nexus Repo](https://help.sonatype.com/repomanager3/product-information/download/download-archives---repository-manager-3) link provided

Copy the download path link from the Nexus download as shown below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698801774190/188266af-d1dc-4183-88cc-d2b47da43c15.png align="center")

Download the Nexus on the server

```bash
wget https://download.sonatype.com/nexus/3/nexus-3.61.0-02-unix.tar.gz
```

Next, it is necessary to extract all of the Nexus files from the archive:

```shell
tar -xvf nexus-3.61.0-02-unix.tar.gz
```

Now, Let's move the Nexus and Sona-type Work (Basically it's the data directory) to the /opt/ folder

```shell
sudo mv nexus-3.61.0-02/ /opt/nexus
sudo mv sonatype-work/  /opt/
```

Now, let's configure the rc file and set the user which is going to run this nexus repo:

```shell
sudo vim /opt/nexus/bin/nexus.rc
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698803734800/2cd4de84-c3c2-4653-8be8-577d0c0b6b69.png align="center")

and save the file,

To prevent permission issues, it is essential to set the correct ownership for the /opt/nexus/ and /opt/sonatype-work/ (i.e., data directory) :

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

You can delete the archive and the Nexus folder once you have finished:

```shell
rm -rf nexus-*
```

Some of these options will be used in the service definition. We'll use Systemd, which is a system and service manager for Linux operating systems. To do so, we need to create a systemd unit configuration file:

```shell
sudo vim /etc/systemd/system/nexus.service
```

Here's the content of the Nexus. service file:

```shell
[Unit]
Description=nexus service
After=network.target
  
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/etc/init.d/nexus start
ExecStop=/etc/init.d/nexus stop 
User=nexus
Group=nexus
Restart=on-abort
TimeoutSec=600

[Install]
WantedBy=multi-user.target
```

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Make sure that you have removed the firewall restrictions for the 8081 port and also create inbound rules in the cloud</div>
</div>

Set the Java path, the following command tells you where the Java is installed

```bash
which java
```

copy the path and link it as shown below

```bash
export INSTALL4J_JAVA_HOME=<java path>
export PATH=/usr/bin/java:$PATH
```

Lastly, we need to set the symbolic link as shown below

```bash
sudo ln -s /opt/nexus/bin/nexus /etc/init.d/nexus
```

Activate the service with the following commands:

```bash
sudo systemctl daemon-reload
```

To ensure Nexus starts automatically after a reboot, enable the service:

```shell
sudo systemctl enable nexus
```

Start nexus:

```shell
/etc/init.d/nexus start
sudo systemctl start nexus
```

1. Check the status of nexus with the following command:
    

```shell
sudo systemctl status nexus
```

Now bring up the browser and enter http://serverip:8081 this will show up the Nexus Repo

Click on the login button. User name is admin but we need to get the password from the server as provided in the password column in the dialog box, lets enter it in the server

```bash
cat /opt/sonatype-work/nexus3/admin.password
```

copy the password and paste it on the server. as soon as you paste it, it will ask you to change the password , change the password and click save.
