If you’re running a modern version of OSX then you’re likely running Java 11, which is fine until you need to run npm/gulp tests with Selenium (which requires Java8).
jenv to the rescue!
assuming you have homebrew installed
1
2
3
| brew tap caskroom/versions
brew cask install java8
brew install jenv
|
then either update your ~/.bash_profile
or (if you have one) ~/.path
file
1
2
| export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
|
& reload your shell.
I also created a bash alias called javaversions
that translates to /usr/libexec/java_home -V
run javaversions
, or /usr/libexec/java_home -V
and copy the last column of for each of the JDKs you’d like to manage with jenv
ie:
$ javaversions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| Matching Java Virtual Machines (13):
11.0.1, x86_64: "OpenJDK 11.0.1" /Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home
11, x86_64: "Java SE 11" /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
11, x86_64: "OpenJDK 11" /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home
10.0.1, x86_64: "Java SE 10.0.1" /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
10, x86_64: "Java SE 10" /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home
9.0.4, x86_64: "Java SE 9.0.4" /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
9.0.1, x86_64: "Java SE 9.0.1" /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home
1.8.0_192, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
1.8.0_92, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home
1.8.0_77, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
1.8.0_72, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home
1.8.0_66, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
1.8.0_60, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
|
now let’s add Java8
jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
you’ll see something like
1
2
3
| $ oracle64-1.8.0.192 added
$ 1.8.0.192 added
[....]
|
now we can run
jenv local 1.8
and then
npm test