How to switch between Java 8 and 11 on Ubuntu?

Asked

Viewed 1,911 times

2

I made a few days ago the transition from Windows 7 to Ubuntu 18.04 LTS, and had some difficulties in the process. Well, let’s get to the details.

I installed JDK 11 through the following command:

sudo apt-get install openjdk-11-openjdk

But I need JDK 8 for some college projects. How can I switch between openjdk 8 and 11? In Windows I was doing modifying the system variable PATH, then I imagine there must be something similar...

1 answer

3


Just update the version of java you want to use. To list all installed versions use the command

update-java-alternatives --list

To update just type the following:

sudo update-java-alternatives --set /caminho/para/versao/java

Where /caminho/para/versao/java may be, for example: /usr/lib/jvm/java-8-openjdk-amd64

  • I used the following command: sudo update-java-alternatives --set /usr/lib/jvm/java-8-openjdk-amd64, but Terminal gave me the following answer: update-java-alternatives: file does not exist: /usr/lib/jvm/.java-8-openjdk-amd64.jinfo. I tried several things, including directing all the way to the archive jinfo from inside the folder /usr/lib/jvm/java-8-openjdk-amd64/bin, but I don’t know what I’m doing wrong, do you have any idea? Thank you.

  • When you turn the remote java -version, what he returns?

  • openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)

  • 1

    From what I understand, it has already changed to version 11. This error, from what I researched, is when a module is not supporting the update-java-alternatives

  • And since he’s not taking it yet, there’s something I can do?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.