Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am having issues updating Java. I am running Ubuntu 11.10.

I can execute sudo apt-get install openjdk-7-jdk and it completes successfully. javac -version is 1.7, however java -version is 1.6. This is similar to this problem but my issue is not, as far as I can tell, the path.

$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Thanks.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Update:

Found a site that has a pretty good explanation: LINK


From the link:

Then we have to do some configuration.
Debian has a script to maintain different version of programs like java called update-alternatives.

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/bin/java 1065
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0/bin/javac 1065

Where 1065 is a given priority.

To check my installation i use –config parameter
update-alternatives --config java
this prints:
There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                      Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/jdk1.7.0/bin/java             1065      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/jdk1.7.0/bin/java             1065      manual mode

And because 1065 is higher than 1061, the fresh installed java 7 will be used by default on my machine java -version
prints:

java version "1.7.0"
 Java(TM) SE Runtime Environment (build 1.7.0-b147)
 Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

Notes: This might make it more understandable.

SLES11 # which java
/usr/bin/java

SLES11 # update-alternatives --list java
/usr/lib64/jvm/jre-1.6.0-ibm/bin/java

SLES11 # update-alternatives --display java
java - status is auto.
 link currently points to /usr/lib64/jvm/jre-1.6.0-ibm/bin/java
/usr/lib64/jvm/jre-1.6.0-ibm/bin/java - priority 1608
 slave rmiregistry: /usr/lib64/jvm/jre-1.6.0-ibm/bin/rmiregistry
 slave tnameserv: /usr/lib64/jvm/jre-1.6.0-ibm/bin/tnameserv
 slave rmid: /usr/lib64/jvm/jre-1.6.0-ibm/bin/rmid
 slave jre_exports: /usr/lib64/jvm-exports/jre-1.6.0-ibm
 slave policytool: /usr/lib64/jvm/jre-1.6.0-ibm/bin/policytool
 slave keytool: /usr/lib64/jvm/jre-1.6.0-ibm/bin/keytool
 slave jre: /usr/lib64/jvm/jre-1.6.0-ibm
Current `best' version is /usr/lib64/jvm/jre-1.6.0-ibm/bin/java.

The man page give the path that the update-alternatives uses for its directory.

SLES11 # pwd
/etc/alternatives

SLES11 # ll
lrwxrwxrwx 1 root root 37 Mar 19 06:03 java -> /usr/lib64/jvm/jre-1.6.0-ibm/bin/java
lrwxrwxrwx 1 root root 28 Mar 19 06:03 jre -> /usr/lib64/jvm/jre-1.6.0-ibm
lrwxrwxrwx 1 root root 28 Mar 19 06:03 jre_1.6.0 -> /usr/lib64/jvm/jre-1.6.0-ibm
lrwxrwxrwx 1 root root 36 Mar 19 06:03 jre_1.6.0_exports -> /usr/lib64/jvm-exports/jre-1.6.0-ibm
lrwxrwxrwx 1 root root 36 Mar 19 06:03 jre_exports -> /usr/lib64/jvm-exports/jre-1.6.0-ibm
lrwxrwxrwx 1 root root 28 Mar 19 06:03 jre_ibm -> /usr/lib64/jvm/jre-1.6.0-ibm
lrwxrwxrwx 1 root root 36 Mar 19 06:03 jre_ibm_exports -> /usr/lib64/jvm-exports/jre-1.6.0-ibm

Making the change if you already have them installed and just need to change the default.

SLES11 # update-alternatives --config java

There is only 1 program which provides java
(/usr/lib64/jvm/jre-1.6.0-ibm/bin/java). Nothing to configure.


Original Answer:

If you look in /etc/java or something like /etc/java-7-openjdk you should see the configuration files.
java.conf or jvm.cfg

This is typically (depending) on the configuration file set your options. You can have several version of java installed at the same time and change the startup variables to effect which one is your default JVM.

from CentOS java.conf

# If you have the a base JRE package installed
# (e.g. java-1.6.0-openjdk):
#JAVA_HOME=$JVM_ROOT/jre

# If you have the a devel JDK package installed
# (e.g. java-1.6.0-openjdk-devel):
#JAVA_HOME=$JVM_ROOT/java 

from Ubuntu jvm.cfg

# List of JVMs that can be used as an option to java, javac, etc.
# Order is important -- first in this list is the default JVM.
# NOTE that this both this file and its format are UNSUPPORTED and
# WILL GO AWAY in a future release.
#
# You may also select a JVM in an arbitrary location with the
# "-XXaltjvm=" option, but that too is unsupported
# and may not be available in a future release.
#
-server KNOWN
-client IGNORE
-hotspot ERROR
-classic WARN
-native ERROR
-green ERROR
-jamvm KNOWN
-cacao KNOWN
-zero KNOWN
-shark ALIASED_TO -zero

On Ubuntu there is a program called update-java-alternatives
This is the top few lines of the man page

NAME
       update-java-alternatives - update alternatives for jre/sdk installations

SYNOPSIS
       update-java-alternatives [--jre] [--plugin] [-t|--test|-v|--verbose]
             -l|--list []
             -s|--set 
             -a|--auto
             -h|-?|--help

DESCRIPTION
       update-java-alternatives  updates  all  alternatives belonging to one runtime or development kit for the Java language.  A package does provide these
       information of it's alternatives in /usr/lib/jvm/..jinfo.
root@ubuntul:/# update-java-alternatives -l  
java-1.6.0-openjdk 1061 /usr/lib/jvm/java-1.6.0-openjdk
 -s|--set 
              Set all alternatives of the registered jre/sdk installation to the program path provided by the  installation.

What I will typically also see are links in /etc/profile.d for java startup environments.

My guess is that your java libraries were installed in the same place and the config files are still defaulting to the original version. You should just need to give the new JVM path.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.