Downgrade open jdk 8 to 7 in ubuntu 14.04

I accidentally updated my entire system in ubuntu 14.04.

I am trying to deploy a war file that requires JDK7.

I tried to install JDK7 and use it as default

root:floyd~# update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Nothing to configure.

      

but it also fails to install. When trying to install JDK 7, it gives the following error.

root@floyd:~# apt-get install openjdk-7-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package openjdk-7-jdk is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

N: Ignoring file '50unattended-upgrades.ucf-dist' in directory '/etc/apt/apt.conf.d/' as it has an invalid filename extension
E: Package 'openjdk-7-jdk' has no installation candidate

      

I think I have two options.

  • Install JDK7 and use it as default.
  • Downgrade JDK8 to JDK7.

I think that a downgrade might be a good option, but I can't do any of them.

+3


source to share


1 answer


Installing JRE / JDK in Default Configuration OpenJDK 7 is installed by default in Ubuntu 12.10 and later. Java installation with which apt-get is easy:

sudo apt-get update

java -version

      

If after execution we have something like: "The java program can be found in the following packages", it means that Java is not installed. So, we need:

sudo apt-get install default-jre

      

The result will be installed Java Runtime Environment (JRE)

. When we want to install Java Development Kit (JDK)

which is required to compile a Java application (for example, Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA), we need to do:

sudo apt-get install default-jdk

      

Java is now installed.

Installation OpenJDK 7

(optional)

sudo apt-get install openjdk-7-jre

      

After completing the installation Java Runtime Environment (JRE)

. For we Java Development Kit (JDK)

perform:

sudo apt-get install openjdk-7-jdk

      


Installing Oracle JDK (optional) The Oracle JDK is the official JDK, but now Oracle does not support it as the default for Ubuntu installation.

We can install it using apt-get, but before we need to run the following commands:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

      

Later we have to select the required version and execute:

For Oracle JDK 6

sudo apt-get install oracle-java6-installer

      

For Oracle JDK 7

sudo apt-get install oracle-java7-installer

      

For Oracle JDK 8

sudo apt-get install oracle-java8-installer

      

For Oracle JDK 9

sudo apt-get install oracle-java9-installer

      

Java control (optional) When we have some version of Java installed, we can choose one of them by default:



sudo update-alternatives --config java

      

As a result, we will see something like this:

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:

      

We see this on the screen: enter image description here

The same action we can do to select the compiler (javac):

sudo update-alternatives --config javac

      

This command can be used to select other java componentenst like: keytool, javadoc and jarsigner.

Installing "JAVA_HOME" To install **JAVA_HOME**

:

sudo update-alternatives --config java

      

Result:

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:

      

As we can see, the paths for java will be:

/usr/lib/jvm/java-7-oracle
/usr/lib/jvm/java-6-openjdk-amd64
/usr/lib/jvm/java-7-oracle

      

Now we need to copy one of the ways and paste it into /etc/environment

::

sudo nano /etc/environment

      

In the file we will add the path (where YOUR_PATH is the path to the desired java version, for example: " /usr/lib/jvm/java-7-oracle

"):

JAVA_HOME="/usr/lib/jvm/java-7-oracle"

      

On the screen: enter image description here

Now we need to reload this file:

source /etc/environment

      

To test this, we can:

echo $JAVA_HOME

      

On the screen: enter image description here

When we now have a way to enter ("/ usr / lib / jvm / java-7-oracle" in our example), it means we are doing it successfully. Otherwise, we need to be more careful and check all these steps once.

+6


source







All Articles