简体   繁体   中英

/usr/bin/alternatives command throws usage error

I'm trying to upgrade my java installation on Oracle Linux 6.5. My VM came with jdk1.6 and I installed jdk1.7 (via rpm). But "java -version" still shows 1.6. As root, I tried /usr/bin/alternatives.

sudo -su root    
/usr/sbin/alternatives –install /usr/bin/java java /usr/java/jdk1.7.0_55/bin/java 17055

But it's not working. I'm getting a usage error but I cannot see what's wrong with my command.

usage: alternatives --install <link> <name> <path> <priority>
....

I checked the link and the path and they look good (I think).

MY-MACHINE:/usr/java/jdk1.7.0_55/bin # ls -al /usr/bin/java
lrwxrwxrwx. 1 root root 22 Jun 12 10:37 /usr/bin/java -> /etc/alternatives/java

MY-MACHINE:/usr/java/jdk1.7.0_55/bin # ls -al /usr/java/jdk1.7.0_55/bin/java
-rwxr-xr-x 1 root root 7718 Mar 17 22:05 /usr/java/jdk1.7.0_55/bin/java

Can anyone else see what I'm doing wrong? Cheers.

应该是- --install两个连字符,而不是– –install破折号或- -install一个连字符。

What gives:

java -version

Check your alternatives java config as root with:

alternatives --display java

You can reconfigure your java setting to point to the Oracle JDK 7 binaries with

alternatives --config java

If you had installed the Oracle JDK 7 Update 55 per:

rpm -ihv jdk-7u55-linux-x64.rpm

The install routine should have created a folder/subfolders and sym-links under /usr/java like this:

default -> /usr/java/latest
jdk1.7.0_55
latest -> /usr/java/jdk1.7.0_55

The following is important when you are using alternatives:

1.) Do the install right (root).In your case:

alternatives --install /usr/bin/java java /usr/java/latest/bin/java 17055

2.) Set the alternatives (root)

alternatives --set java /usr/java/latest/bin/java 

3.) Config the alternatives (root)

alternatives --config java

On my Oracle Linux 6.6 I get 3 choices:

There are 3 programs which provide 'java'.

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

Enter to keep the current selection[+], or type selection number:3

Choose 3 and you are done!

4.) Proove your Java Env

java -version

it should show you the Oracle JDK 7 Update 55

java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

Hint: If you want to use javac, javaws or other tools from the Oracle JDK 7 then you must do this procedure accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM