简体   繁体   English

如何在同一台机器上设置不同的 Scala 版本?

[英]How to setup different Scala versions on the same machine?

I want to follow the book on Scala[1] but it uses Scala 3 and I have Scala 2 installed.我想关注关于 Scala[1] 的书,但它使用 Scala 3 并且我安装了 Scala 2。 I want to use both the versions, something on the lines of python2 and python3 .我想使用这两个版本,在python2python3行。

I tried installing Scala3 on my local using the official source but I could only grasp the project-level working directory.我尝试使用官方源在本地安装 Scala3,但我只能掌握项目级工作目录。 The sbt prompt does not work like a REPL would and I can only open REPL using Scala 2 (I checked the version everytime). sbt提示符不像 REPL 那样工作,我只能使用 Scala 2 打开 REPL(我每次都检查版本)。

How do I open the REPL of Scala3 given I cannot uninstall Scala2?鉴于无法卸载 Scala2,如何打开 Scala3 的 REPL?

The sbt prompt does not work like a REPL sbt 提示不像 REPL 那样工作

If you execute sbt console from within project directory it will drop you into REPL version corresponding to the project's scalaVersion .如果您从项目目录中执行sbt console ,它将使您进入与项目的scalaVersion对应的 REPL 版本。 For example, executing sbt console within project created with sbt new lampepfl/dotty.g8 would start Scala 3 REPL.例如,在使用sbt new lampepfl/dotty.g8创建的项目中执行sbt console将启动 Scala 3 REPL。

but I could only grasp the project-level working directory但我只能掌握项目级工作目录

For system-wide installation first install coursier and then execute cs install scala3-repl .对于系统范围的安装,首先安装 coursier ,然后执行cs install scala3-repl This will install Scala 3 REPL alongside the Scala 2 one.这将在 Scala 2 旁边安装 Scala 3 REPL。 Now Scala 3 REPL can be started with scala3-repl command whilst Scala 2 REPL simply with scala command.现在 Scala 3 REPL 可以使用scala3-repl命令启动,而 Scala 2 REPL 只需使用scala命令即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM