divya.trehan573
divya.trehan573

Reputation: 564

how to find the exact location where java is installed in unix

I am using SSH Client. I have run the environment variable still

echo $JAVA_HOME is not returning anything. I want to find the exact location where the java is installed in unix. is there any other command which can help me with this ?

Upvotes: 5

Views: 26614

Answers (7)

Shivam Anand
Shivam Anand

Reputation: 1611

You can very easily find the Java Home Directory by appending /jre to the output directory of the below command

sudo update-java-alternatives -l

Sample output will be

java-11-oracle                 1091       /usr/lib/jvm/java-11-oracle

Now append /jre which makes the JAVA HOME as

/usr/lib/jvm/java-11-oracle/jre

Upvotes: 0

Kedar1442
Kedar1442

Reputation: 217

Try this

$ which java

might result output as

/usr/bin/java

Upvotes: 1

Ankit
Ankit

Reputation: 6622

since echo $JAVA_HOME is not giving you the path, this variable is probably not already set. Instead, which command would give you the path.

which java

Note that, this might not give you the exact location if command is a symlink. If that is the case, you must resolve the symlink through other methods. say readlink or through python (os.path.realpath(path))

Upvotes: 5

dudel
dudel

Reputation: 692

The which command gives you the path to the java binary:

which java

But if it is only a symlink (e.g. used by alternatives) this will not get your the real path to the binary. You can either list where the symlink points to with with ls -l:

ls -l `which java`

which for me outputs

/usr/bin/java -> /etc/alternatives/java

and then follow the symlinks until you are at the source. Alternatively, if available on your system, use the readlink command in combination with -f which follows symlinks for you:

readlink -f `which java`

Edit: Ankit wrote in the comments that readlink is not a standard UNIX command and -f also does not seem to work on a mac, so this may not be an option for you, although this page describes how to get greadlink to get this functionality on a mac via brew:

brew install coreutils greadlink -f which java

Upvotes: 8

Sid
Sid

Reputation: 901

You can try with these 2 commands

$ which java

$ whereis java

Upvotes: 1

Patryk Rogosch
Patryk Rogosch

Reputation: 306

Can you run ? whereis java

As far as I remmember it gives symbolic link to location.

Upvotes: 3

Cédric O.
Cédric O.

Reputation: 101

On Unix you should be able to use the 'which java' command.

https://en.wikipedia.org/wiki/Which_(Unix)

Upvotes: 2

Related Questions