Where is JAVA_HOME on macOS Mojave (10.14) to Lion

2019-01-01 06:10发布

Java is an optional package on the latest versions of macOS.

Yet once installed it appears like the JAVA_HOME environment variable is not set properly.

标签: java macos
24条回答
萌妹纸的霸气范
2楼-- · 2019-01-01 06:29

I Had to explicitly set it to the exact path on my Macbook air .

Steps followed:

  1. try to echo $JAVA_HOME (if it's set it'll show the path), if not, try to search for it using sudo find /usr/ -name *jdk
  2. Edit the Bash p with - sudo nano ~/.bash_profile
  3. Add the exact path to JAVA Home (with the path from step 2 above) export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
  4. Save and exit
  5. Check JAVA_Home using - echo $JAVA_HOME

I am running MACOS MOJAVE - 10.14.2 (18C54) on a Macbook Air with JAVA 8

查看更多
泪湿衣
3楼-- · 2019-01-01 06:30

Anyone using AUSKEY from the Australian Tax Office (ATO) should uninstall AUSKEY. This sorted out my JAVA_HOME issues.

It is also no longer required for MAC users. Yah!

查看更多
余生请多指教
4楼-- · 2019-01-01 06:31

For Mac Yosemite,

JDK 1.7.0_xx is using

$ ls -ltar /usr/bin/java
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.7.0_xx.jdk/Contents/Home
查看更多
旧时光的记忆
5楼-- · 2019-01-01 06:32

Got the same issue after I upgrade my Mac OS and following worked for me:

  1. cmd>vi ~/.bash_profile

  2. Add/update the line for JAVA_HOME: export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk/Contents/Home"

  3. cmd>source ~/.bash_profile or open a new terminal

I think the jdk version might differ, so just use the version which you have under /Library/Java/JavaVirtualMachines/

查看更多
旧人旧事旧时光
6楼-- · 2019-01-01 06:35

For me, Mountain Lion 10.8.2, the solution most voted does not work. I installed jdk 1.7 via Oracle and maven from homebrew.

My solution is from the hadoop-env.sh file of hadoop which I installed from homebrew, too. I add the below sentence in ~/.bash_profile, and it works.

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

This solution also works for OS X Yosemite with Java 1.8 installed from Oracle.

查看更多
看风景的人
7楼-- · 2019-01-01 06:35

The following worked for me. I'm using ZSH on OSX Yosemite with Java 8 installed.

The following command /usr/libexec/java_home emits the path to JDK home:

/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home

In your ~/.zshrc,

export JAVA_HOME = "/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home"
查看更多
登录 后发表回答