Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

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 ?

like image 699
divya.trehan573 Avatar asked Dec 01 '22 16:12

divya.trehan573


1 Answers

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

like image 179
dudel Avatar answered Dec 04 '22 04:12

dudel