如何在Mac上安装OpenJDK 8和SBT,并将OpenJDK 8(而不是13)设置为默认版本?

huangapple go评论95阅读模式
英文:

How can I install openjdk 8 and sbt on mac and have openjdk 8 (not 13) the default one?

问题

安装Java 8和sbt可以使用brew和/或brew cask进行,我遇到的问题是brew将Java 13安装为sbt的依赖项,我不知道回到Java 8作为默认版本的通用方法,因为可能有很多种选择Java版本的方式,其中一些我知道的包括PATH,JAVA_HOME,ln -s,java_exec选择器。另一个潜在的问题是,brew install sbt会安装brew install java,而这是Java 13,但我通过brew cask安装的是Java 8。TL表示Java 13或14可能会导致一些问题,例如测试失败,我是否应该坚持使用OpenJdk,Scala,SBT的最新版本?

英文:

Installing java 8 and sbt with brew and/or brew cask is clearly possible,
The problem I am hitting is that brew installs java 13 as sbt dependency,

And I do not know a general way to go back to java 8 as default, since there are so many ways potentially to opt between java version some of which i am aware include PATH, JAVA_HOME, ln -s, java_exec selector.

Another problem potentially is that brew install sbt installs brew install java which is 13,
But java 8 I install it via brew cask.

The TL is saying that Java 13 or 14 might be causing some issues e.g. tests fails, should I push for latest versions of OpenJdk, Scala, SBT, etc?

答案1

得分: 5

的确,SDK Man是一个选择。
它实际上也适用于brew,但只需要进行一些手动步骤:以下是这些步骤:

安装sbt、java8、jenv并配置Shell

我们使用brew安装sbt(它会安装java 13),并使用brew cask安装openjdk java 8,就像这样:

brew install sbt
brew tap AdoptOpenJDK/openjdk
brew cask install adoptjava8

我们将使用jenv来管理java版本,具体信息请参见https://github.com/Homebrew/homebrew-core/issues/31390

基本上,接下来的步骤是:

brew install jenv
jenv init -
echo 'eval "$(jenv init -)"' >> ~/.bash_profile
echo 'eval "$(jenv init -)"' >> ~/.zprofile
jenv add <path-to-java8-Home-Dir>

然后重新启动你的终端,现在你应该能够运行sbt

在撰写时,<path-to-java8-Home-Dir>/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

英文:

Indeed, SDK Man is an option.
It actually works with brew also but there need to be just a few manual steps: here they are:

Installing sbt, java8, jenv & configure the shell

We used brew to install sbt (which in its turn installs java 13), and brew cask to install openjdk java 8, like this:

brew install sbt
brew tap AdoptOpenJDK/openjdk
brew cask install adoptjava8

We will use jenv to manage the java versions, with the information from https://github.com/Homebrew/homebrew-core/issues/31390

Basically the next steps are:

brew install jenv
jenv init -
echo &#39;eval &quot;$(jenv init -)&quot;&#39; &gt;&gt; ~/.bash_profile
echo &#39;eval &quot;$(jenv init -)&quot;&#39; &gt;&gt; ~/.zprofile
jenv add &lt;path-to-java8-Home-Dir&gt;

Then restart your terminal and you should now be able to run sbt

Where at time of writing &lt;path-to-java8-Home-Dir&gt; is /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

答案2

得分: 3

看看类似 Sdk Man 这样的工具。

它是跨平台的,允许您将任何所需的JDK设置为默认版本。

同时,在需要时还可以将其更改为另一个提供程序/版本。

英文:

Have a look at a utility like Sdk Man.

It is multi-platform and allows you to set any desired JDK as a default one.

As well as changing it to another provider/version when it will be required.

huangapple
  • 本文由 发表于 2020年4月7日 03:13:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/61067260.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定