闲来无事,装个Hbase玩玩,突然发现Mac下默认安装的JDK7,没有配置JAVA_HOME没有那么就自己配呗。
打开之前配置Hadoop集群时配置Java环境的笔记,找到添加环境变量这一步:
[plain] view plain copy print ?
1. export JAVA_HOME=/usr/java/latest
2. export CLASSPATH=.:$JAVA_HOME
3. export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/binexport CLASSPATH=.:$JAVA_HOME/lib:$CLASSPATH
之前是linux环境下配置的,现在换到另一个类Unix系统MacOS下来,想来也是类似的。只要找到JDK的真实安装路径即可。
刚好之前在配置maven依赖的JDK依赖有点类似经验。
[plain] view plain copy print ?
1. shuchen-2:bin seishuchen$ which java
2. /usr/bin/java
3. shuchen-2:bin seishuchen$ ls -la /usr/bin/java
4. lrwxr-xr-x 1 root wheel 74 Mar 4 2014 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
5. shuchen-2:bin seishuchen$
很快找到了当前JDK的真实路径。查看路径名发现,有Versions字段还有Current字段,作为一个程序猿,这点敏感还是有的。
马上切换到Versions目录下面,查看:
[plain] view plain copy print ?
1. shuchen-2:Versions seishuchen$ cd /System/Library/Frameworks/JavaVM.framework/Versions
2. shuchen-2:Versions seishuchen$ ls -al
3. total 72
4. drwxr-xr-x 12 root wheel 408 Jul 15 17:13 .
5. drwxr-xr-x 12 root wheel 408 Apr 11 15:10 ..
6. lrwxr-xr-x 1 root wheel 10 Mar 4 2014 1.4 -> CurrentJDK
7. lrwxr-xr-x 1 root wheel 10 Mar 4 2014 1.4.2 -> CurrentJDK
8. lrwxr-xr-x 1 root wheel 10 Mar 4 2014 1.5 -> CurrentJDK
9. lrwxr-xr-x 1 root wheel 10 Mar 4 2014 1.5.0 -> CurrentJDK
10. lrwxr-xr-x 1 root wheel 10 Mar 4 2014 1.6 -> CurrentJDK
11. lrwxr-xr-x 1 root wheel 10 Mar 4 2014 1.6.0 -> CurrentJDK
12. drwxr-xr-x 8 root wheel 272 Mar 4 2014 A
13. lrwxr-xr-x 1 root wheel 1 Mar 4 2014 Current -> A
14. lrwxr-xr-x 1 root wheel 58 Jul 15 17:12 CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents
15. lrwxr-xr-x 1 root wheel 59 Mar 4 2014 CurrentJDK_BAK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
结果很明显,有木有,原来都指向了/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents
那么就切换过去瞅瞅呗。
[plain] view plain copy print ?
1. shuchen-2:Versions seishuchen$ cd /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents
2. shuchen-2:Contents seishuchen$ ls
3. Home Info.plist MacOS
4. shuchen-2:Contents seishuchen$ cd Home/
5. shuchen-2:Home seishuchen$ ls
6. COPYRIGHT bin man
7. LICENSE db release
8. README.html include src.zip
9. THIRDPARTYLICENSEREADME-JAVAFX.txt jre
10. THIRDPARTYLICENSEREADME.txt lib
11. shuchen-2:Home seishuchen$
看到了久违的JDK安装目录了不是。好了,我们的JAVA_HOME即是/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home。
过程看着挺复杂的样子,当然这个是对于一个最原始的方法,如果你熟悉Mac的话,其实有个获得JAVA_HOME的自带小工具,直接在命令行
输入/usr/libexec/java_home来获得。
[plain] view plain copy print ?
1. shuchen-2:Home seishuchen$ /usr/libexec/java_home
2. /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
3. shuchen-2:Home seishuchen$
那么接下来只要修改配置文件使之生效即可。根据你的需求,可以选择修改不同的环境变量配置文件。
而笔者只是修改当前用户的即可。只要在~/.profile(mac下也可以编辑~/.bashrc,但~/.bash_profile就不确定了,感兴趣的可以自己事先)
加入:
[plain] view plain copy print ?
1. JAVA_HOME=`/usr/libexec/java_home`
2. export JAVA_HOME
3.
4. export CLASSPATH=.:$JAVA_HOME
5. export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
6. export CLASSPATH=.:$JAVA_HOME/lib:$CLASSPATH
接着source ~/.profile ,好了,收工。
执行Hbase启动脚本,用jps查看一下情况,发现一切是那么完美,哦哈哈