在macOS 上添加 JAVA_HOME 環境變量


If you are planing to develop Java Apps on your Mac, you may have to set $JAVA_HOME environment variable.

Install the latest Java Virtual Machine

Go to How to install JDK on Mac OS X to install a new Java Virtual Machine. Download the latest Java JDK package from Oracle.

Check Java Virtual Machines

List directories in the following root -> /Library/Java/JavaVirtualMachines

$ ls -l /Library/Java/JavaVirtualMachines drwxr-xr-x 3 root wheel 102 23 dic 20:36 jdk1.8.0_66.jdk drwxr-xr-x 3 root wheel 102 21 mar 14:20 jdk1.8.0_74.jdk 

And the version for java will be the latest.

$ java -version java version "1.8.0_74" Java(TM) SE Runtime Environment (build 1.8.0_74-b02) Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode) 
Set JAVA_HOME environment variable

Open your terminal, and create .bash_profile file if it does not exist.

vim .bash_profile 

And write the following:

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

Refresh the environment variables by running the following command, and check the $JAVA_HOME value:

$ source .bash_profile $ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home



簡單的說就是先安裝JDK,然后找到 .bash_Profile (因為我不會用vim)。
在最后一行添加

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

然后在命令行里輸入
source .bash_profile

然后查看結果:
echo $JAVA_HOME




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM