Downgrade open jdk 8 to 7 in ubuntu 14.04

假装没事ソ 提交于 2019-12-07 14:04:59

问题


I accidentally upgraded the whole system in ubuntu 14.04.

I am trying to deploy a war file which 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 is not installing as well. It gives following error while trying to install JDK 7.

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 guess I have two options.

  1. Install JDK7 and use it as default.
  2. Downgrade JDK8 to JDK7.

I think downgrading can be a good option but I am not able to do any of them.


回答1:


Installing JRE/JDK in default configuration OpenJDK 7 is installed as default in Ubuntu 12.10 and later. Installing Java whereby apt-get is easy:

sudo apt-get update

java -version

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

sudo apt-get install default-jre

As result, Java Runtime Environment (JRE) will be installed. When we want to install Java Development Kit (JDK), which is needed for compilling Java-app (for example, Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA) we need to do:

sudo apt-get install default-jdk

Now, Java is installed.

Installing OpenJDK 7 (optionally)

sudo apt-get install openjdk-7-jre

After execution Java Runtime Environment (JRE) will be installed. For Java Development Kit (JDK), we execute:

sudo apt-get install openjdk-7-jdk

Installing Oracle JDK (optionally) Oracle JDK is an official JDK but, now, Oracle doesn't support it like default for installation in Ubuntu.

We can install it by apt-get but before we need to execute next commands:

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

Later, we have to choose needed 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

Managing of Java (optionally) When we have some version Java installed we can choose one of them as default:

sudo update-alternatives --config java

As 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 can see it on the screen:

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

sudo update-alternatives --config javac

This command can be used to choose other java componenst, for example, like: keytool, javadoc and jarsigner.

Installing "JAVA_HOME" To be installed **JAVA_HOME**:

sudo update-alternatives --config java

Result like:

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 are going to add a path(where YOUR_PATH - is path for desired version of java, for example: "/usr/lib/jvm/java-7-oracle"):

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

On the screen:

Now, we need to reboot this file:

source /etc/environment

To check it we can:

echo $JAVA_HOME

On the screen:

When we have, now, input way("/usr/lib/jvm/java-7-oracle" in our example) it will be means we do it sucessfully. In other way we need to be more attentive and check all these steps once.



来源:https://stackoverflow.com/questions/44118443/downgrade-open-jdk-8-to-7-in-ubuntu-14-04

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!