My mac mini m2 homebrew had corrupted, I had to fix it.
I am having Java20 installed on Mac, to manage Java versions, I found materials, including fixing no remote repo, brew cask, tap, etc.
For no origin:
cd /opt/homebrew/Library/Taps/homebrew/homebrew-services
git remote add origin https://github.com/Homebrew/homebrew-services
安装Java8
1. 打开终端,输入以下命令安装brew:
`/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
2. 安装Java8:
`brew tap caskroom/versions`
`brew install java8 --cask` mkdir -p ~/.jenv/versions
3. 验证Java8是否安装成功:
`java -version`
如果显示Java8的版本信息,则表示安装成功。
配置多个Java版本
1. 安装jenv:
`brew install jenv` echo 'eval "$(jenv init -)"' >> ~/.bash_profile source ~/.bash_profile brew install --cask adoptopenjdk@11 $ jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home jenv versions jenv local/global 11.0 java -version
2. 添加Java版本:
`jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home`
`jenv add /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home`
可以添加多个Java版本。
3. 列出已安装的Java版本:
`jenv versions`
4. 设置全局Java版本:
`jenv global 1.8`
或者
`jenv global 11.0.2`
5. 设置本地Java版本:
`jenv local 1.8`
或者
`jenv local 11.0.2`
设置本地Java版本后,当前目录下的Java版本会被设置为指定版本。
6. 设置Shell的Java版本:
`jenv shell 1.8`
或者
`jenv shell 11.0.2`
设置Shell的Java版本后,当前Shell的Java版本会被设置为指定版本。
7. 验证Java版本是否设置成功:
`java -version`
如果显示设置的Java版本信息,则表示设置成功。 |
zsh to make, global, shell, local commands take effect:
notice the setby path in jenv versions output, if set by ~/.java-version, delete it to make jenv global use the version instead to take effect. Enable plugins for export, maven, gradle etc.
Scopes:
global( everywhere in OS), local( this folder/project), shell( this shell session)
refs:
using jenv:
https://www.cnblogs.com/softidea/p/17791084.html
installing jdk8:
https://www.jianshu.com/p/fb8f2e36a5a8
jenv usage:
https://akrabat.com/using-jenv-to-select-java-version-on-macos/
https://devqa.io/switch-between-different-java-versions-mac/