在Amazon Linux中切换到JDK 7

时间:2013-11-20 22:27:36

标签: java linux amazon-ec2 java-7

我有t1.micro 64位实例,我按照一些指令(sudo yum install java-1.7.0-openjdk-devel)(sudo yum update等)安装了JDK 7。所以,当我搜索它时,

sudo yum search openjdk

我得到了关注 -

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

所以,两者都已安装。但是当我尝试使用

切换到JDK 7时
sudo update-alternatives --config java 

我明白了 -

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java

为什么只显示6?

我尝试了其他命令,如 -

sudo update-alternatives --set javac /usr/lib/jvm/java-7-openjdk/bin/javac

但没有成功。

1 个答案:

答案 0 :(得分:13)

要确保安装了openjdk 7,请运行以下命令。

# rpm -qa | grep openjdk

如果已安装,则应列出1.6和1.7。如果它只列出1.6(就像我猜的那样),那么sudo update-alternatives --config java工作正常,您需要通过运行yum -y install java-1.7.0-openjdk来安装jdk 7

这是我机器的输出:

# 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: