For my research, I do need at least two different Java versions (6.0 and 7.0 or above) on my Mac OS X. I found this tool jEnv is very useful and the Andrew’s “ Managing multiple versions of Java on OS X” is helpful.
- Check Current Java Version
$ java -version java version "1.6.0_65" Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716) Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode) $ /usr/libexec/java_home /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home $ ls /System/Library/Java/JavaVirtualMachines/ 1.6.0.jdk
Installation of jEnv
- Install
$brew install jenv ==> Downloading https://homebrew.bintray.com/bottles/jenv-0.4.3.yosemite.bottle.tar.gz ######################################################################## 100.0% ==> Pouring jenv-0.4.3.yosemite.bottle.tar.gz ==> Caveats To enable shims and autocompletion add to your profile: if which jenv > /dev/null; then eval "$(jenv init -)"; fi To use Homebrew's directories rather than ~/.jenv add to your profile: export JENV_ROOT=/usr/local/opt/jenv ==> Summary 🍺 /usr/local/Cellar/jenv/0.4.3: 74 files, 308K
- Follow the instruction
$ echo 'if which jenv > /dev/null; then eval "$(jenv init -)"; fi' >> .bash_profile
- Check
$ jenv versions * system (set by /Users/ykf_2001/.jenv/version)
Installation of Java 8
- Download and install it manually from Oracle
- Check it
$java -version java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode) $ /usr/libexec/java_home /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home $ ls /Library/Java/JavaVirtualMachines/ jdk1.8.0_45.jdk
- So now the OS comes with Java 8
- List all javas installed
$ /usr/libexec/java_home -verbose Matching Java Virtual Machines (3): 1.8.0_45, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home 1.6.0_65-b14-466.1, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Add of old Java 6 and Java 8 to jEnv
$ jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
oracle64-1.6.0.65 added
1.6.0.65 added
1.6 added
$ jenv versions
* system (set by /Users/ykf_2001/.jenv/version)
1.6
1.6.0.65
oracle64-1.6.0.65
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/
oracle64-1.8.0.45 added
1.8.0.45 added
1.8 added
$ jenv versions
* system (set by /Users/ykf_2001/.jenv/version)
1.6
1.6.0.65
1.8
1.8.0.45
oracle64-1.6.0.65
oracle64-1.8.0.45
Configurations
- Set global Java version to Java 8
$ jenv global oracle64-1.6.0.65 $ jenv versions system 1.6 1.6.0.65 1.8 1.8.0.45 * oracle64-1.6.0.65 (set by /Users/ykf_2001/.jenv/version) oracle64-1.8.0.45 $ jenv global oracle64-1.8.0.45 $ jenv versions system 1.6 1.6.0.65 1.8 1.8.0.45 oracle64-1.6.0.65 * oracle64-1.8.0.45 (set by /Users/ykf_2001/.jenv/version) $ cat ~/.jenv/version oracle64-1.8.0.45 $ java -version java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
- Set the Java 6 for local directories
~/Programs/eclipse-kepler-for-czt$ jenv local oracle64-1.6.0.65 ~/Programs/eclipse-kepler-for-czt$ jenv versions system 1.6 1.6.0.65 1.8 1.8.0.45 * oracle64-1.6.0.65 (set by /Users/ykf_2001/Programs/eclipse-kepler-for-czt/.java-version) oracle64-1.8.0.45 ~/Programs/eclipse-kepler-for-czt$ cd ~/Workspace/czt-code-20150622/ ~/Workspace/czt-code-20150622$ jenv local oracle64-1.6.0.65 ~/Workspace/czt-code-20150622$ jenv versions system 1.6 1.6.0.65 1.8 1.8.0.45 * oracle64-1.6.0.65 (set by /Users/ykf_2001/Workspace/czt-code-20150622/.java-version) oracle64-1.8.0.45
why is it displaying 1.6 1.6.0.65 and oracle64-1.6.0.65 aren't they same?
ReplyDelete