JDK download and install
Java Downloads official website
On the above official website page, we can download the latest JDK19or17, or download the current mainstream JDK8or11.
Select the JDK version and computer version you need, download and install it.
If Mac chooses dmg installation, it will automatically configure the environment variables. If you choose the compressed package, you need to configure the environment variables after decompressing.
Multi-version JDK environment
Taking bloggers as an example, JDK11 is generally used to develop Android programs; but only JDK8 can be used to make cocos2.4.9 game packaging environment.
Therefore, we need to configure a multi-version JDK environment by brew+jenv
implementing version switching.
Jenv is similar to pynev and can switch the JDK environment, but it cannot install JDK. You need to download and install multiple versions yourself and add them with the add command.
brew
Install brew to see brew official website home page
jenv
jenv official document
jenv github homepage
- Install jenv using brew
brew install jenv
- Configure environment variables
#Bash
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile
#Zsh
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc
- Java Downloads download official website to install different versions of JDK
- Add JDK to jenv
jenv add PATH_TO_JVM_HOME
- The JDK installed by dmg is in the default
/Library/Java/JavaVirtualMachines/
location and can bejenv add /Library/Java/JavaVirtualMachines/jdk_version/Contents/Home/
added. - Add the default jdk of AndroidStudio as:
jenv add /Applications/Android\ Studio.app/Contents/jbr/Contents/Home
- The JDK installed by dmg is in the default
- View the JDK version added to jenv
jenv versions
, * is the currently selected version by default.
* system (set by /Users/user/.jenv/version)
11.0
11.0.2
openjdk64-11.0.2
- Switch to the specified version
jenv shell <version>-- 只为当前 shell 会话选择
jenv local <version>-- 当你在当前目录(或其子目录)时自动选择
jenv global <version>-- 为您的用户帐户全局选择
jenv global
The terminal needs to be restarted after switching.