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

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

April 11, 2021 11 min read 4 views 0 discussions
Table of Contents

    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)-[~]
    └─$
    ┌──(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)-[~]
    └─$
    ┌──(kali㉿kali)-[~]
    └─$ cd Downloads                  
    ┌──(kali㉿kali)-[~/Downloads]
    └─$ sudo mv jdk-8 /usr/lib/jvm 
    ┌──(kali㉿kali)-[~/Downloads]
    └─$ 
    ┌──(kali㉿kali)-[~/Downloads]
    └─$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-8/bin/java 1
    ┌──(kali㉿kali)-[~/Downloads]
    └─$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-8/bin/javac 1
    ┌──(kali㉿kali)-[~/Downloads]
    └─$
    ┌──(kali㉿kali)-[~/Downloads]
    └─$ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-8/bin/jar 1
    ┌──(kali㉿kali)-[~/Downloads]
    └─$
    ┌──(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:
    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]
    └─$
    ┌──(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]
    └─$ 
    ┌──(kali㉿kali)-[~]
    └─$ javac -version
    Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
    javac 17.0.8
    ┌──(kali㉿kali)-[~]
    └─$ 
    ┌──(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)-[~]
    └─$ 
    ┌──(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)-[~]
    └─$ 
    ┌──(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)-[~]
    └─$ 

    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. 

    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. 

    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.

    Now, let's execute the following command: 

    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.

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

    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. 

    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."

    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.

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

    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.

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

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

    You have successfully installed JAVA 8 on your Kali Linux.

    Community Q&A