java home – echo $JAVA_HOME not returning jdk location

java home – echo $JAVA_HOME not returning jdk location

Try echo %JAVA_HOME% instead of echo $JAVA_HOME.

The first is for Windows (Im assuming its windows based on your filepath), the one youre using is for Linux.

In my case, when I typed echo $JAVA_HOME I was getting blank, and I resolved it by following these instructions:

$ vim .bash_profile

export JAVA_HOME=$(/usr/libexec/java_home)

$ source .bash_profile

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

Reference:
https://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/

java home – echo $JAVA_HOME not returning jdk location

In Ubuntu you may setup and confirm the environment variable like this:

~$ sudo apt install default-jdk
~$ sudo nano /etc/environment
# ADD below line
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
~$ source /etc/environment
~$ echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64

Above commands are:

  1. install jdk
  2. edit environment file
  3. apply edited environment variable
  4. show $JAVA_HOME

Leave a Reply

Your email address will not be published.