This chapter describes how to install java as it might be a dependancy for our work. For example Spark requires Java 8.
This is not a guide for writing Java code.
If you just want the quick commands for the installation.
brew install cask jenv brew tap caskroom/versions brew cask install java java8
You will also need to edit your .bash_profile. See below.
We assume you already have installed Homebrew to get packages for Mac OS.
You will need cask.
brew install cask
Tap cask versions to get access to older versions of java.
brew tap caskroom/versions
Install Java 8. This installation will require that you input your password near the end, before the installation can complete.
brew cask install java8
If you want or need the latest Java version.
brew cask install java
JDKs will be installed at the following directories. Your JDKs versions might be different.
This is a tool for creating Java virtual environments.
brew install jenv
Open this file for editing (using whatever editor).
if which jenv > /dev/null; then eval "$(jenv init -)"; fi
Then source your bash_profile file
We will be using jEnv to create Java virtual environments. Official jEnv docs
jEnv doesn’t install JDKs, so we have to tell jEnv where to look for them. Type these commands to register JDKs in jEnv (replace the versions with yours):
jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/ jenv add /Library/Java/JavaVirtualMachines/jdk10.0_2.jdk/Contents/Home/
After that, run this command to list all registered JDKs:
You can set global Java version like this:
jenv global 10.0
And in your project folder you can use another version like this: You can set global Java version like this:
cd my-project-folder jenv local 1.8
The above command will create a .java-version file at project root.