Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have been using Java 6 on Ubuntu 11.10, but now I want to update to version 7. I've installed version 7 via PPA as described here. If I run

sudo update-alternatives --config java

I get the following output:

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   64        auto mode
  1            /usr/lib/jvm/java-6-sun/jre/bin/java      63        manual mode
* 2            /usr/lib/jvm/java-7-oracle/jre/bin/java   64        manual mode

Similarly, if I run:

sudo update-alternatives --config javac

I get the output:

  Selection    Path                                  Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-oracle/bin/javac   64        auto mode
  1            /usr/lib/jvm/java-6-sun/bin/javac      63        manual mode
* 2            /usr/lib/jvm/java-7-oracle/bin/javac   64        manual mode

So it looks like version 7 is already the default. But if I run either

java -version

or

javac -version

The output indicates that version 6 is still the default. How can I set the default to version 7?

share|improve this question
    
Have a look at Java –  Mitch Jun 16 '13 at 6:06
    
@Mitch thanks, but it just says to use update-alternatives, which I've already tried –  Dónal Jun 16 '13 at 21:55
    
did you sudo apt-get install oracle-java7-set-default and reboot? –  Eliran Malka Jun 16 '13 at 22:05
1  
FYI, 11.10 is End of Life. –  Thomas W. Jun 16 '13 at 22:31

4 Answers 4

You need to set javac too.

sudo update-alternatives --config javac
share|improve this answer

insert the number that identifies the path you want and press enter. in this case insert 1.

finally, try to test the version java -version

share|improve this answer
    
I want version 7, not 6. The output of update-alternatives indicating that I'm already using version 7, but java -version shows that I'm still using version 6. –  Dónal Jun 16 '13 at 21:48

As per this answer: How to set default Java version?

Try providing the explicit path along with update-alternatives --install first, and then run update-alternatives to make your selection:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-7-oracle/jre/bin/java" 1

sudo update-alternatives --config java

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-7-oracle/bin/javac" 1

sudo update-alternatives --config javac
share|improve this answer

I guess your java binary is pointing to somewhere other than /etc/alternatives/java.

Check the output of: type java

Does it say /usr/bin/java? If so, then check if that points correctly to alternatives:

ls -l /usr/bin/java should show it pointing to /etc/alternatives/java.

Lastly confirm that /etc/alternatives/java itself is pointing to java-7:
ls -l /etc/alternatives/java.

The update-alternatives command only adjusts the last one and assumes that default points to /usr/bin/java which in turn is correctly linked to /etc/alternatives/java.

share|improve this answer

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.