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

brew tap caskroom/versions
brew cask install java8
brew install jenv

then either update your ~/.bash_profile or (if you have one) ~/.path file

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


$ javaversions

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

$ oracle64- added
$ added

now we can run

jenv local 1.8

and then

npm test