Java 在 Amazon Linux 中切换到 JDK 7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20108411/
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
Switch to JDK 7 in Amazon Linux
提问by onlinenaman
I have t1.micro 64-bit instance, where I installed JDK 7 following some instructions (sudo yum install java-1.7.0-openjdk-devel
)(sudo yum update
etc). So, when I search for it,
我有 t1.micro 64 位实例,我按照一些说明 ( sudo yum install java-1.7.0-openjdk-devel
)(sudo yum update
等)在其中安装了 JDK 7 。所以,当我搜索它时,
sudo yum search openjdk
I get following-
我得到以下-
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
So, both are installed. But when I try to switch to JDK 7 using
所以,两者都安装了。但是当我尝试切换到 JDK 7 时使用
sudo update-alternatives --config java
I get-
我明白了——
There is 1 program that provides 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
Why is it showing only the 6?
为什么只显示6个?
I tried other commands like-
我尝试了其他命令,例如-
sudo update-alternatives --set javac /usr/lib/jvm/java-7-openjdk/bin/javac
but no success.
但没有成功。
回答by slayedbylucifer
To ensure that openjdk 7 is installed, run below command.
要确保安装了 openjdk 7,请运行以下命令。
# rpm -qa | grep openjdk
It should list 1.6 and 1.7 if you have both installed. If it lists only 1.6 (as in your case I would guess), then sudo update-alternatives --config java
is working fine and you need to install jdk 7 by running yum -y install java-1.7.0-openjdk
如果您同时安装了 1.6 和 1.7,它应该列出。如果它只列出 1.6(就像我猜的你的情况),那么sudo update-alternatives --config java
工作正常,你需要通过运行来安装 jdk 7yum -y install java-1.7.0-openjdk
Here is the output from my machine:
这是我机器的输出:
# rpm -qa | grep openjdk
java-1.7.0-openjdk-1.7.0.45-2.4.3.2.32.amzn1.x86_64
java-1.6.0-openjdk-1.6.0.0-65.1.11.14.57.amzn1.x86_64
# update-alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
2 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
Enter to keep the current selection[+], or type selection number: