I'm trying to learn how to quickly change which java version my system uses as described in this article: https://aboullaite.me/switching-between-java-versions-on-ubuntu-linux/ I've used apt-get install openjdk-8-jdk, and when I run sudo update-alternatives --config java it looks like this:

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      manual mode
* 2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

I'm trying to create a script that will switch between versions, like in the article. (this is the script from the article:

sudo update-java-alternatives -s java-8-oracle
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/

but when I try it, this happens:

sudo update-java-alternatives -s java-8-openjdk-amd64
update-java-alternatives: file does not exist: /usr/lib/jvm/.java-8-openjdk-amd64.jinfo

How can I update-java-alternatives without an error? Should I just skip that line?

2 Answers 2


First run command:

sudo update-alternatives --get-selections | grep "/bin/jinfo"

Ideally this file should be there.

Secondly, check the files under /usr/lib/jvm. Do ls -la inside this, you must see a link such as below:

lrwxrwxrwx   1 root root    20 Nov  9 10:37 java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64

Use this to run alternatives command:

sudo update-java-alternatives -s java-1.8.0-openjdk-amd64


Workaround that fix the problem above

sudo update-java-alternatives -s java-1.8.0-openjdk-amd64

You must log in to answer this question.

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