The first step is to install homebrew
For specific operations, please refer to Mac installation homebrew.
The second step is to execute the command
brew install jenv
Step 3: Add environment variables
Add the following content to the .zshrc file via the command vim ~/.zshrc
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
The specific operation is
command+space.
Search terminal to open.
Enter vim ~/.zshrc on the terminal command line
and enter i to switch to input mode.
After pasting the above content, press esc to enter colon ':', and enter wq and then enter.
Pay attention to the lower left corner of the terminal.
This is installed.
How to use the fourth step
Check which java versions are available
jenv versions
Add a new java version (there is a folder bin under the java installation path)
jenv add "java的安装路径如/usr/local/opt/java/Contents/Home/"
switch java version
jenv global 17
Finally, enter java -version to verify whether the switch is successful.