4

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 .

karel
  • 122,292
  • 133
  • 301
  • 332
Geemo
  • 143

5 Answers5

6

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.

karel
  • 122,292
  • 133
  • 301
  • 332
1

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

janasaiarun
  • 192
  • 2
  • 17
0

The answer is no more applicable for Version 16.04 and 18.04.

For 18.04, view this answer: How can i install jdk7 on ubuntu 18.04 lts 64bit? by Cliffton Fernandes

Additional information: The tar.gz file is no more available on the oracle web pages but can be found at CERN: http://monalisa.cern.ch/MONALISA/download/java/

Best regards, Karsten

0

[Written on 22-09-2019]

To install openjdk-7-jdk on Ubuntu 18.04 (wsl), these steps worked for me.

The error seems to point out that a new version is available, so it is not allowing to install the older version.

Solution: modify sources.list (/etc/apt/sources.list) with 14.04 sources

Please comment and let others know if it worked for you.

nagato
  • 1
  • 1
0

Now, Ubuntu 18 has removed apt support for Java 7.

The best possible option is to download tar.gz file from https://jdk.java.net/java-se-ri/7

After downloading tar.gz file, extract it and follow from Step # 3 (Setting environment variables) in https://techoral.com/blog/java/install-openjdk-7-ubuntu.html