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 .

  • 2
    Have a look at askubuntu.com/questions/740757/…. – mattias Dec 31 '17 at 1:16
  • 1
    Ok, I alredy installed java 8 but I don't know how to install java 7 – Geemo Dec 31 '17 at 1:34
  • 1
    @mattias That link answers half of the question. What are you going to do about answering the other half? Geemo is probably using either Ubuntu 16.04 or Ubuntu 17.10 because Ubuntu 17.04 will be EOL within a month. – karel Dec 31 '17 at 5:51
  • Have a look here.. howtodojo.com/2017/07/install-java-7-ubuntu-16-04 – janasaiarun Jan 1 '18 at 13:59
  • Welcome to Ask Ubuntu! We’re sorry, but Ask Ubuntu is not a forum, but a Question & Answer site: it works best if you ask one question, so you can receive one answer. When you ask multiple questions, you need to find one expert versed in multiple areas, which becomes unlikelier the more questions you put into, well, one question! ;-) So please, split up your question into multiple questions and drop me a comment so I can answer one of your questions. – David Foerster Jan 1 '18 at 14:48
5

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.

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

  • The OP can't find Java 7 which is in 14.04 but he can find Java 8 which is not in 14.04, so by both counts it appears that the OP is not using Ubuntu 14.04. Otherwise by some magic trick the OP would have managed to see the package that is not there in 14.04 while overlooking the package that is there in 14.04, so if you have to guess what release the OP is using a better guess would be either 16.04 or 17.10. – karel Dec 31 '17 at 7:23
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.

  • There are a few issues with this answer: (a) Trusty (14.04) is EOL, (b) This is not the correct answer, or the way to do this setup. (c) This can have many unintended consequences, and when you go back to 16.04 sources.list, it will upgrade the java installation. – Domo N Car Sep 22 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.