# How to install OpenJDK 18 or JDK 18 on Kali Linux

By default, the Kali Linux ISO (2023.X) ships with OpenJDK 17, and some of the Kali Linux tools may require OpenJDK 18. But JDK 18 has reached its end of support. But no need to worry in this blog we will cover how you can install OpenJDK 18 also known as JAVA 18 on your running Kali Linux Machine. So let's start.

**Step 1: Open your terminal and log in as a root user**

Simply, open your terminal and log in as the root user in your Kali Linux machine by using the following command:

```bash
sudo su -
```

**Step 2: Download the JDK 18 Release**

All deprecated JDK releases can be found on the official [JDK Archive](https://jdk.java.net/archive/). From there select *18.0.2 (build 18.0.2+9)* as the version and download the *Linux/x64 64-bit tar.gz* file. You can use wget for it.

```bash
wget https://download.java.net/java/GA/jdk18.0.2/f6ad4b4450fd4d298113270ec84f30ee/9/GPL/openjdk-18.0.2_linux-x64_bin.tar.gz
```

**Step: 3 Extract the file**

Now once your JDK 18.0.2 has been successfully downloaded extract the file using the following command.

```bash
tar xvzf openjdk-18.0.2_linux-x64_bin.tar.gz 
```

**Step 4: Confirm the version of the new JVM using the**

Then you should verify the version of this new JVM.

```bash
cd jdk-18.0.2/bin
./java -version
```

You should then get an output like this.

```plaintext
openjdk version "18.0.2" 2022-07-19
OpenJDK Runtime Environment (build 18.0.2+9-61)
OpenJDK 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing)
```

**Step 5: Move the JDK folder to the preferred location**

Now again change your directory and move the JDK 18 folder to the preferred location.

```bash
cd ../../
mv jdk-18.0.2 /usr/lib/jvm/jdk-18.0.2
```

**Step 6: Export the JAVA\_PATH**

Once you are all done our final step is to export the Java path to our `.bashrc` or `.zshrc` file.

Note: If you have `.zshrc` then no need to export it to the `.bashrc`. Nowadays all new Kali Linux installation comes with ZSH so you only need to update `.zshrc` .

```bash
nano .zshrc

# If you don't have .zshrc then only
nano .bashrc
```

Then move your cursor to the bottom of the file and paste this 2 there.

```bash
export JAVA_HOME="/usr/lib/jvm/jdk-18.0.2"
export PATH="$JAVA_HOME/bin:$PATH"
```

Then save it using `Ctrl+S` and then close it using `Ctrl + X` .

Now you can refresh the path for the terminal.

```bash
source ~/.zshrc

# If you don't have .zshrc then only
source ~/.bashrc
```

Now we are done installing JDK 18 for the root user now we need to do it for the regular user.

For that first exit as the root user. Run this command on your terminal.

```bash
exit
```

Then again open `.zshrc` or `.bashrc` and put the same thing there.

```bash
nano .zshrc

# If you don't have .zshrc then only
nano .bashrc
```

In the file bottom add:

```bash
export JAVA_HOME="/usr/lib/jvm/jdk-18.0.2"
export PATH="$JAVA_HOME/bin:$PATH"
```

Now you can refresh the path for the terminal.

```bash
source ~/.zshrc

# If you don't have .zshrc then only
source ~/.bashrc
```

Now we are all done and you can now close your terminal and restart it and you will have JDK 18 used by default on your terminal. And you can verify it by just running `java -version` or `sudo java -version` on your terminal.

So that's all if this article helped then please like and share this article with your friends and if you need any help or you are stuck then comment with your problem and hopefully I'll provide you with a solution.

If you want a video tutorial then also please do comment and I'll try to make it.
