1

I am trying to configure java home on ubuntu VM. Compared to windows, things seems to be pretty complex and confusing.

I installed jdk 8 using 'sudo apt-install....', so when I check version:

java -version openjdk version "1.8.0.62"

When I do, 'which java', I get:

/usr/bin/java

But /usr/bin/java is a file, not a directory.

When I do, 'whereis java', I get three entries:

/usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz

But I don't see jdk installed at these locations.

On some more google search, I find that its actually /usr/lib/jvm where jdk is installed.

So what are all these locations in file system? And have I done correct thing by pointing JAVA_HOME to /usr/lib/jvm/.... ?

Mandroid
  • 6,200
  • 12
  • 64
  • 134
  • You don't need to do this manually. Just use `update-alternatives` – Jorn Jun 23 '23 at 13:16
  • Why this downvote?Anything wrong with question? – Mandroid Jun 23 '23 at 13:16
  • I don't think it should be downvoted but what are you trying to do? The only case where you should configure JAVA_HOME by hand, is if you have multiple different java versions installed and need to switch between them. (And in that case, use update-alternatives instead). – MTilsted Jun 23 '23 at 13:18
  • @MTilsted After installing jdk, when I do 'echo JAVA_HOME', it returns no result. That's why I tried to do it manually. – Mandroid Jun 23 '23 at 13:19
  • 1
    To find out where it really is, you want `readlink -f "$(which java)"` Depending on how you want to develop, you might use something like `alias j18='export JAVA_HOME=/usr/lib/jvm/bellsoft-java18-amd64;export PATH=$JAVA_HOME/bin:$PATH'` but then you'd need to continue in that shell. That's what I do though as it enables me to quickly switch between versions. Probably quicker and not global like `update-alternatives` – g00se Jun 23 '23 at 13:19
  • But you do in general not need JAVA_HOME for anything. Are you trying to do something specific, which require JAVA_HOME? – MTilsted Jun 23 '23 at 13:22
  • You only need a JAVA_HOME style variable if you wish to call as `$JAVA_HOME/bin/java`, otherwise it is the PATH variable you need to check so you can call using `java`. – DuncG Jun 23 '23 at 13:22

1 Answers1

1

java versions are indeed located in /usr/lib/jvm/

you want your JAVA_HOME to look something like this:

/usr/lib/jvm/java-17-openjdk-amd64

if you want to set your JAVA_HOME globaly, use this:

How to set JAVA_HOME in Linux for all users

"So what are all these locations in file system?"

/usr/bin/java is the executable, which executes the java you set in JAVA_HOME, the actual executable is located in ${JAVA_HOME}/bin and all other files of java are located in the JAVA_HOME directory