Mac上配置不同版本的JDK

Mac上JDK的版本为1.8,编译AOSP时发现需要JDK 1.7。想找一种比较容易切换JDK版本的方式,经过一番Google发现Jenv比较合适。

安装Jenv至少有三种方式:

- $ git clone https://github.com/gcuisinier/jenv.git ~/.jenv
- $ curl -L -s get.jenv.io | bash
- $ brew install jenv

我是用第三种方式安装的。

安装后运行
    
    jenv doctor

报了两个错误。

1.类似于:
        
    Jenv is not loaded in your $shell"
    To fix : \tcat eval "$(jenv init -)" >>' $profile

说明在.bash_profile中缺少相应的配置。
    
    $ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
    $ echo 'eval "$(jenv init -)"' >> ~/.bash_profile

直接写入配置即可fix这个错误;

2.类似于:
    
    Java binary in path is not in the jenv shims.
    Please check your path, or try using `jenv add /path/to/java/home`.

找到Mac下JDK的位置(/Library/Java/JavaVirtualMachine/jdk1.7.0_79.jdk/Contents/Home),运行jenv add加入。

jenv doctor返回全部正确后进行下一步操作。运行类似jenv global jdk1.7.0_79.jdk的命令即可自由切换版本。

Reference:
- [Github](https://github.com/gcuisinier/jenv)
- [jenv](http://jenv.io/)

 

posted @ 2015-04-26 18:38  BlueMountain_79  阅读(512)  评论(0编辑  收藏  举报