Installing Java 7 in 16.04 and using multiple Java versions
I already installed Java 8, but I don't know how to install Java 7 and how to switch between the two Java versions.
I also want to switch between Java 7 and 8 to update a project I am working on. I am a new Ubuntu user, so be very specific.
added: 12/31/2017
gero@4790k:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
When I try to use:
gero@4790k:~$ sudo apt-get install openjdk-7-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package openjdk-7-jdk is a virtual package provided by:
oracle-java9-installer 9.0.1-1~webupd8~0
oracle-java8-installer 8u151-1~webupd8~0
oracle-java7-installer 7u80+7u60arm-0~webupd8~1
You should explicitly select one to install.
E: Package 'openjdk-7-jdk' has no installation candidate
I don't even know how to select the the java installer 7u80.
Or if you can tell me how to install jdk-7u80-linux-x64.tar.gz or jdk-7u80-linux-x64.rpm .
Solution 1:
The openjdk-7-jdk package is available in Ubuntu 14.04. Although you don't have Ubuntu 14.04 currently installed, you can keep using the Ubuntu version that you have and install Ubuntu 14.04 as a guest OS in VirtualBox. I recommend that you keep the Ubuntu 14.04 VirtualBox guest OS files for as long as you need to use Java 7 and also make backups of these files.
To install openjdk-7-jdk in Ubuntu 14.04 run:
sudo apt-get install openjdk-7-jdk
Java 7 is also available at the Java SE 7 Archive Downloads webpage of the official Oracle website. Select the .tar.gz file which is currently named jdk-7u80-linux-x64.tar.gz (for 64-bit architecture) or jdk-7u80-linux-i586.tar.gz (for 32-bit architecture) and follow the installation instructions at this answer. Oracle gives this warning that the packages in the Oracle Java Archive packages are no longer updated with the latest security patches.
These older versions of the JRE and JDK are provided to help developers debug issues in older systems. They are not updated with the latest security patches and are not recommended for use in production.
openjdk-8-jdk is not included in the Ubuntu 14.04 default repositories, so install the Oracle Java 8 JDK version by following the instructions from: How can I install Sun/Oracle's proprietary Java JDK 6/7/8 or JRE?. You can use either sudo update-alternatives --config java
(update-alternatives is provided by default by dpkg in Ubuntu) or update-java-alternatives
(which is installed when openjdk-9-jdk is installed) to manually choose which Java to use before running an application. See update-java-alternatives vs update-alternatives --config java.
Solution 2:
You didn't mention which version of ubuntu you are using. I presume as 14.04.
As you said that you have already installed java 8. Install java 7 by following command:
sudo apt-get install openjdk-7-jdk.
Then you can switch Java versions by the following command:
sudo update-alternatives --config java
Select the version that you need and press enter. You can check which version you are using by command: java -version