For Mac OSX 10.5 or later
In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME
variable to /usr/libexec/java_home
,
just export $JAVA_HOME
in file ~/. bash_profile
or ~/.profile
.
1 2 3 4 5 6 7 8 9 |
$ vim .bash_profile <span class="token function">export</span> JAVA_HOME<span class="token operator">=</span><span class="token variable">$(/usr/libexec/java_home) </span> $ <span class="token function">source</span> .bash_profile $ <span class="token keyword">echo</span> <span class="token variable">$JAVA_HOME</span> /Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home |
For Linux
For each user, user can add the java path in ~/. bash_profile
or ~/.profile
.
For all users, system admin can add the java path in /etc/profile
To find java path location, try one of followings
- update-java-alternatives -l
- cd /
find . -name ‘javac’ //might need root privilege - alternatives –display java
- sudo update-alternatives –config java
- Or take look at the following
– /usr/local/java/jdk[version]
– /usr/lib/jvm/java-1.11.0-openjdk-amd64
– /usr/lib/jvm/java-1.8.0-openjdk
Once the JDK path is found, we can add into ~/.bash_profile or ~/.profile as following,
export JAVA_HOME=”path that you found”
export PATH=$JAVA_HOME/bin:$PATH
For Windows (*Reference : mkyong blog
Find System Properties (*My Computer > Right Click > Properties)
Add JAVA_HOME
ADD JAVA Bin PATH //Window 7
ADD JAVA Bin PATH //Window 10
Last Step, Let’s run some test
1 2 3 4 5 6 7 8 9 |
C:\Users\FRank<span class="token operator">></span>java -version java version <span class="token string">"1.8.0_231"</span> Java<span class="token punctuation">(</span>TM<span class="token punctuation">)</span> SE Runtime Environment <span class="token punctuation">(</span>build 1.8.0_231<span class="token punctuation">)</span> C:\Users\FRank<span class="token operator">></span>javac -version javac 1.8.0_231 C:\Users\FRank<span class="token operator">></span>echo %JAVA_HOME% C:\Program Files\Java\jdk1.8.0_231 |
以上為安裝JDK 軟體後 ,需做的基本路徑設定。
也希望對各位初學者或是想找路徑的朋友 有些幫助 ~
以上
時賦科技 FRank