Home > Software engineering >  wsl: 'which java/whereis java' give wrong information
wsl: 'which java/whereis java' give wrong information

Time:06-30

I have installed wsl2,and then installed jdk 17. Now I want to configure JAVA_HOME. When I do:

$ which java
/usr/bin/java
$ whereis java
java: /usr/bin/java

But I don't see any java folder in /usr/bin.

Instead, I found java in /usr/lib/jvm:

$ pwd
/usr/lib/jvm
$ ls
java-1.17.0-openjdk-amd64  java-17-openjdk-amd64

Why so?

CodePudding user response:

Because java isn't a folder, it's a binary, and probably a link to one of the binaries in jvm directory. You can check where the Java application points to by using ls -al /usr/bin/java

JAVA_HOME shouldn't point to the Java binary, but to one of the directories you've listed in the second example, so something like JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64.

I'd recommend having a look at jenv btw, it helps a lot in switching JDKs should you need it.

  • Related