java 在 ubuntu 14.04 中将 open jdk 8 降级到 7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44118443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Downgrade open jdk 8 to 7 in ubuntu 14.04
提问by Aaditya Bhatta
I accidentally upgraded the whole system in ubuntu 14.04.
我不小心在 ubuntu 14.04 升级了整个系统。
I am trying to deploy a war file which requires JDK7.
我正在尝试部署一个需要 JDK7 的 war 文件。
I tried to install JDK7 and use it as default
我尝试安装 JDK7 并将其用作默认值
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.
但它也没有安装。尝试安装 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.
我想我有两个选择。
- Install JDK7 and use it as default.
- Downgrade JDK8 to JDK7.
- 安装 JDK7 并使用它作为默认值。
- 将 JDK8 降级到 JDK7。
I think downgrading can be a good option but I am not able to do any of them.
我认为降级可能是一个不错的选择,但我不能做任何一个。
回答by Vasyl Lyashkevych
Installing JRE/JDK in default configurationOpenJDK 7 is installed as default in Ubuntu 12.10 and later. Installing Java whereby apt-get is easy:
在默认配置中安装 JRE/JDKOpenJDK 7 在 Ubuntu 12.10 及更高版本中默认安装。安装 Java apt-get 很容易:
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:
如果执行后我们有类似:“程序java可以在以下包中找到”,则表示未安装Java。所以,我们需要:
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:
结果,Java Runtime Environment (JRE)
将被安装。当我们要安装Java Development Kit (JDK)
编译 Java-app(例如 Apache Ant、Apache Maven、Eclipse 和 IntelliJ IDEA)所需的 时,我们需要执行以下操作:
sudo apt-get install default-jdk
Now, Java is installed.
现在,Java 已安装。
Installing OpenJDK 7
(optionally)
安装OpenJDK 7
(可选)
sudo apt-get install openjdk-7-jre
After execution Java Runtime Environment (JRE)
will be installed. For Java Development Kit (JDK)
, we execute:
执行后Java Runtime Environment (JRE)
就会安装。对于Java Development Kit (JDK)
,我们执行:
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.
安装 Oracle JDK(可选)Oracle JDK 是一个官方的 JDK,但是,现在,Oracle 并不像在 Ubuntu 中默认安装那样支持它。
We can install it by apt-get but before we need to execute next commands:
我们可以通过 apt-get 安装它,但在我们需要执行下一个命令之前:
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
对于 Oracle JDK 6
sudo apt-get install oracle-java6-installer
For Oracle JDK 7
对于 Oracle JDK 7
sudo apt-get install oracle-java7-installer
For Oracle JDK 8
对于 Oracle JDK 8
sudo apt-get install oracle-java8-installer
For Oracle JDK 9
对于 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:
管理 Java(可选)当我们安装了某个版本的 Java 时,我们可以选择其中之一作为默认值:
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:
The same action we can do to choose the compiler (javac):
我们可以执行相同的操作来选择编译器 (javac):
sudo update-alternatives --config javac
This command can be used to choose other java componenst, for example, like: keytool, javadoc and jarsigner.
该命令可用于选择其他 java 组件,例如:keytool、javadoc 和 jarsigner。
Installing "JAVA_HOME"To be installed **JAVA_HOME**
:
安装“JAVA_HOME”要安装**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:
正如我们所看到的,java 的路径是:
/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
:
现在,我们需要复制其中一种方式并将其粘贴到
/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
"):
在文件中,我们将添加一个路径(其中 YOUR_PATH - 是所需版本的 java 的路径,例如:“ /usr/lib/jvm/java-7-oracle
”):
JAVA_HOME="/usr/lib/jvm/java-7-oracle"
Now, we need to reboot this file:
现在,我们需要重新启动这个文件:
source /etc/environment
To check it we can:
要检查它,我们可以:
echo $JAVA_HOME
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.
当我们现在有了输入方式(在我们的例子中是“/usr/lib/jvm/java-7-oracle”)时,这将意味着我们成功地做到了。换句话说,我们需要更加专心并检查所有这些步骤一次。