Really common question today is - "How I can install and use several Java versions on my OSX without a headache?", so here's my answer.
Just follow simple and straightforward steps below (yes I did check those before publishing):
1. Check if You already have java installed:
$ java -version
2. If You have java locally then check location of installed version:
- installed from Apple -
/System/Library/Java/JavaVirtualMachines/1.X.X.jdk/Contents/Home/
- installed from Oracle -
/Library/Java/JavaVirtualMachines/jdk1.X.X_XX.jdk/Contents/Home
Remember that path.
3. Check if You have homebrew installed if not install it first:
- http://brew.sh/
4. Install jenv with homebrew:
$ brew install jenv
5. Add information about jenv into Your .bash_profile or .bashrc file:
if which jenv > /dev/null; then eval "$(jenv init -)"; fi
6. Save and reload .bashrc / .bash_profile:
$ source .bashrc (.bash_profile)
7. Check that jenv works properly:
$ jenv versions
This command should have next output by default:
$ * system (set by /Users/ajones/.jenv/version)
8. Add Your installed local java to jenv:
$ sudo jenv add /Library/Java/JavaVirtualMachines/jdkX.X.X_XX.jdk/Contents/Home/
Check if this added with jenv versions command.
9. Install cask with homebrew:
$ brew install cask
10. Install latest java from Oracle:
$ brew cask install java
Currently (March 2016) this command installs jdk1.8.0_74.jdk from Oracle.
11. Add latest installed java into jenv as peviously:
$ sudo jenv add /Library/Java/JavaVirtualMachines/jdkX.X.X_XX.jdk/Contents/Home/
12. Run jenv versions and verify that now You have 2 java versions installed on Your local machine
13. If You want to switch to needed version run:
$ sudo jenv local oracle64-1.7.X.XX or
$ sudo jenv local oracle64-1.8.X.XX
14. After each command You can run:
$ java -version
in order to check which java version is currently active.
15. If You want to change java version to all users:
$ sudo jenv global oracle64-1.7.X.XX or
$ sudo jenv global oracle64-1.8.X.XX
You can install as many java versions as You want - just add them to the jenv and then simply do switch when needed.
Just follow simple and straightforward steps below (yes I did check those before publishing):
1. Check if You already have java installed:
$ java -version
2. If You have java locally then check location of installed version:
- installed from Apple -
/System/Library/Java/JavaVirtualMachines/1.X.X.jdk/Contents/Home/
- installed from Oracle -
/Library/Java/JavaVirtualMachines/jdk1.X.X_XX.jdk/Contents/Home
Remember that path.
3. Check if You have homebrew installed if not install it first:
- http://brew.sh/
4. Install jenv with homebrew:
$ brew install jenv
5. Add information about jenv into Your .bash_profile or .bashrc file:
if which jenv > /dev/null; then eval "$(jenv init -)"; fi
6. Save and reload .bashrc / .bash_profile:
$ source .bashrc (.bash_profile)
7. Check that jenv works properly:
$ jenv versions
This command should have next output by default:
$ * system (set by /Users/ajones/.jenv/version)
8. Add Your installed local java to jenv:
$ sudo jenv add /Library/Java/JavaVirtualMachines/jdkX.X.X_XX.jdk/Contents/Home/
Check if this added with jenv versions command.
9. Install cask with homebrew:
$ brew install cask
10. Install latest java from Oracle:
$ brew cask install java
Currently (March 2016) this command installs jdk1.8.0_74.jdk from Oracle.
11. Add latest installed java into jenv as peviously:
$ sudo jenv add /Library/Java/JavaVirtualMachines/jdkX.X.X_XX.jdk/Contents/Home/
12. Run jenv versions and verify that now You have 2 java versions installed on Your local machine
13. If You want to switch to needed version run:
$ sudo jenv local oracle64-1.7.X.XX or
$ sudo jenv local oracle64-1.8.X.XX
14. After each command You can run:
$ java -version
in order to check which java version is currently active.
15. If You want to change java version to all users:
$ sudo jenv global oracle64-1.7.X.XX or
$ sudo jenv global oracle64-1.8.X.XX
You can install as many java versions as You want - just add them to the jenv and then simply do switch when needed.
No comments:
Post a Comment