Echo $Java_Home Not Returning Jdk Location

Echo $Java_Home Not Returning Jdk Location

When I type in echo $JAVA_HOME, I get $JAVA_HOME instead of the location of the jdk. I set the path from the environment variables correctly:

Variable name : JAVA_HOME Variable value: C:\Program Files\Java\jdk1.7.0_25

what am I doing wrong?

4 Answers

Try echo %JAVA_HOME% instead of echo $JAVA_HOME.

The first is for Windows (I'm assuming it's windows based on your filepath), the one you're using is for Linux.

0

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:

1

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

Linux:

$ vi ~/.bash_profile

export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

$ source ~/.bash_profile

Verification:

$ echo $JAVA_HOME

$ echo $PATH

$ which java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.