2

I'm using Ubuntu 14.04 with multiple java versions. I'm trying to change the current java version for my user with:

sudo update-alternatives --config java
sudo update-alternatives --config javac

I change to the right one but when I do:

java -version

I still receive the old one. When I do:

sudo java -version

I receive the new one.

I need the new java version to be set for my user (without sudo).

How can I do it?

2 Answers 2

2

As far as I know, update-alternatives can only be set globally.

If you want to use a different version of java at any time, specify the full path on the command line or in the script, or if this is for applications that will check JAVA_HOME, set JAVA_HOME at the end of your ~/.profile:

JAVA_HOME=/path/to/java/version/I/want

or export the above in the shell to use only in the current session

1

The problem was with my JAVA_HOME variable
Had to add:

export JAVA_HOME=path/to/correct/version

then everything worked.

2
  • When I execute echo $JAVA_HOME is empty. How do I update my java version
    – Robert
    Apr 29, 2015 at 20:28
  • I guess: from playing with different versions this variable was already set (and pointed to the wrong version).
    – guntbert
    Aug 20, 2017 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .