Java Installation – Installing Java 7 on Ubuntu 16.04 and Managing Multiple Versions

javaopenjdksoftware installation

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 .

Best Answer

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?. Switch between Java 7 and Java 8 by following the instructions from: Switch between multiple java versions. update-java-alternatives and update-alternatives commands list the jre/jdk installations and the paths to their executable files and provides a way of switching between Java versions.