How to fix 'Openjdk-8' has no installation candidate?

During my attempt to install JDK-8 using the command, sudo apt-install openjdk-8-jdk, I encountered an error stating "Unable to locate package." 

┌──(kali㉿kali)-[~]
└─$ sudo apt install openjdk-8-jdk
[sudo] password for kali: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package openjdk-8-jdk
                                                                                                                               
┌──(kali㉿kali)-[~]
└─$

To address this issue, I'll guide you through the manual installation of JDK-8. You can apply similar steps to install other versions as well.


Open your preferred web browser, and navigate to this URL. 


Oracle Java 8 - Download

This link provides access to download Oracle Java 8. Java 8 is a widely used version of the Java programming language, known for its stability and compatibility with many applications.


This webpage will offer access to the installation and archive files for JDK-8. 

We'll specifically target the Linux version for installation. However, you'll notice various architecture options available. To determine your system's architecture, execute the command "uname -a" in your terminal. 

┌──(kali㉿kali)-[~]
└─$ uname -a
Linux kali 6.3.0-kali1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.3.7-1kali1 (2023-06-29) x86_64 GNU/Linux
                                                                                                                               
┌──(kali㉿kali)-[~]
└─$

Upon checking the result, I discovered that my system employs the x86_64 architecture. Consequently, I will download the x64 archive file. After completing the download, the next step is to prepare for the installation of JDK-8. 

Navigate to the directory where the download is located. 

Once there, extract the downloaded file. 

After extraction, rename the folder to, "jdk-8." 

To proceed, move this renamed folder to the /usr/lib/jvm directory. Open a new terminal and navigate to the download directory and Execute the "mv" command to relocate the folder to its new destination.

┌──(kali㉿kali)-[~]
└─$ cd Downloads                  
                                                                                                                               
┌──(kali㉿kali)-[~/Downloads]
└─$ sudo mv jdk-8 /usr/lib/jvm 
                                                                                                                               
┌──(kali㉿kali)-[~/Downloads]
└─$ 

Now, let's execute the following command: 

┌──(kali㉿kali)-[~/Downloads]
└─$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-8/bin/java 1

This command instructs the system to add a new alternative for the Java executable. It designates the new alternative's location as `/usr/lib/jvm/jdk-8/bin/java` and assigns it a priority of 1. This means that if other alternatives for the `java` command exist, the system will give preference to the one specified in this command with a priority value of 1. This approach proves valuable for managing multiple versions of a program and seamlessly switching between them.

Similarly, we proceed to add new alternatives for other executables. Replace the word "java" with "javac" to add a new alternative for the Java compiler.

┌──(kali㉿kali)-[~/Downloads]
└─$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-8/bin/javac 1
                               
┌──(kali㉿kali)-[~/Downloads]
└─$

And then repeat the process for the "jar" command.

┌──(kali㉿kali)-[~/Downloads]
└─$ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-8/bin/jar 1
                                                                                                                               
┌──(kali㉿kali)-[~/Downloads]
└─$

Having successfully installed Java 8, the next step is to configure it as the default Java runtime environment (JRE) interactively. This configuration is especially handy when dealing with multiple installed Java versions, and you wish to designate one as the default.

To achieve this, enter the command `sudo update-alternatives --config java` in the terminal. 

┌──(kali㉿kali)-[~/Downloads]
└─$ sudo update-alternatives --config java 
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-17-openjdk-amd64/bin/java   1711      auto mode
  1            /usr/lib/jvm/java-17-openjdk-amd64/bin/java   1711      manual mode
  2            /usr/lib/jvm/jdk-8/bin/java                   1         manual mode

Press <enter> to keep the current choice[*], or type selection number:

This command prompts the system to present you with two alternative options for Java. You'll need to choose the number corresponding to the location of jdk-8 and press "Enter."

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/jdk-8/bin/java to provide /usr/bin/java (java) in manual mode
                                                                                                                                
┌──(kali㉿kali)-[~/Downloads]
└─$

By following this step, you'll effectively update Kali Linux to use Java 8. In case you wish to revert to the previous Java version, simply execute a similar command and select the desired alternative.

┌──(kali㉿kali)-[~/Downloads]
└─$ java -version                         
java version "1.8.0_381"
Java(TM) SE Runtime Environment (build 1.8.0_381-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.381-b09, mixed mode)
                                                                                                                                
┌──(kali㉿kali)-[~/Downloads]
└─$ 

These steps provide a robust mechanism for managing different Java versions of your system.

┌──(kali㉿kali)-[~]
└─$ javac -version
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
javac 17.0.8
                                                                                                                                
┌──(kali㉿kali)-[~]
└─$ 

However, the Java compiler has not yet been updated to version 8 yet. To achieve this, run the same command as before, but replace "java" with "javac." Then select the alternative "javac" option when prompted.

┌──(kali㉿kali)-[~]
└─$ sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                          Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-17-openjdk-amd64/bin/javac   1711      auto mode
  1            /usr/lib/jvm/java-17-openjdk-amd64/bin/javac   1711      manual mode
  2            /usr/lib/jvm/jdk-8/bin/javac                   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/jdk-8/bin/javac to provide /usr/bin/javac (javac) in manual mode
                                                                                                                                
┌──(kali㉿kali)-[~]
└─$ javac -version
javac 1.8.0_381
                                                                                                                                
┌──(kali㉿kali)-[~]
└─$ 

Likewise, proceed to update the path for the jar file. 

┌──(kali㉿kali)-[~]
└─$ sudo update-alternatives --config jar 
There are 2 choices for the alternative jar (providing /usr/bin/jar).

  Selection    Path                                        Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-17-openjdk-amd64/bin/jar   1711      auto mode
  1            /usr/lib/jvm/java-17-openjdk-amd64/bin/jar   1711      manual mode
  2            /usr/lib/jvm/jdk-8/bin/jar                   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/jdk-8/bin/jar to provide /usr/bin/jar (jar) in manual mode
                                                                                                                                
┌──(kali㉿kali)-[~]
└─$ 

Once these changes are made, you can verify them by checking the version:

┌──(kali㉿kali)-[~/Downloads]
└─$ java -version                         
java version "1.8.0_381"
Java(TM) SE Runtime Environment (build 1.8.0_381-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.381-b09, mixed mode)
                                                                                                                                
┌──(kali㉿kali)-[~]
└─$ javac -version
javac 1.8.0_381
                                                                                                                                
┌──(kali㉿kali)-[~]
└─$ 

You have successfully installed JAVA 8 on your Kali Linux.

Tags

Post a Comment

2 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
  1. Thanks for the guide btw, i get difficult when i try to move the file to /usr/lib/jvm. Turns out the one who moved is the extracted files

    ReplyDelete
  2. I keep reading a lot of posts when I first get into trouble. This is how I once reached this website (https://kodlogs.net/340/unable-to-locate-package-openjdk-8-jre) and got the desired solution. You can read this post as well as visit here. I think it will be very useful for you

    ReplyDelete

If you have any doubts or any queries you can specify here.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!