如何在同一台机器上设置不同的 Scala 版本? [英] How to setup different Scala versions on the same machine?

查看:57
本文介绍了如何在同一台机器上设置不同的 Scala 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习关于 Scala[1] 的书,但它使用 Scala 3,我安装了 Scala 2.我想同时使用这两个版本,python2python3 行上的东西.

I want to follow the book on Scala[1] but it uses Scala 3 and I have Scala 2 installed. I want to use both the versions, something on the lines of python2 and python3.

我尝试使用官方来源在本地安装Scala3,但我只能掌握项目级别工作目录.sbt 提示不像 REPL 那样工作,我只能使用 Scala 2 打开 REPL(我每次都检查版本).

I tried installing Scala3 on my local using the official source but I could only grasp the project-level working directory. The sbt prompt does not work like a REPL would and I can only open REPL using Scala 2 (I checked the version everytime).

我无法卸载 Scala2,如何打开 Scala3 的 REPL?

How do I open the REPL of Scala3 given I cannot uninstall Scala2?

推荐答案

sbt 提示不像 REPL 那样工作

The sbt prompt does not work like a REPL

如果您从项目目录中执行 sbt console,它会将您带入与项目的 scalaVersion 相对应的 REPL 版本.例如,在使用 sbt new lampepfl/dotty.g8 创建的项目中执行 sbt console 将启动 Scala 3 REPL.

If you execute sbt console from within project directory it will drop you into REPL version corresponding to the project's scalaVersion. For example, executing sbt console within project created with sbt new lampepfl/dotty.g8 would start Scala 3 REPL.

但是我只能抓到项目级的工作目录

but I could only grasp the project-level working directory

对于系统范围的安装,首先安装 coursier 然后执行 cs安装 scala3-repl.这将与 Scala 2 REPL 一起安装 Scala 3 REPL.现在 Scala 3 REPL 可以使用 scala3-repl 命令启动,而 Scala 2 REPL 只需使用 scala 命令.

For system-wide installation first install coursier and then execute cs install scala3-repl. This will install Scala 3 REPL alongside the Scala 2 one. Now Scala 3 REPL can be started with scala3-repl command whilst Scala 2 REPL simply with scala command.

这篇关于如何在同一台机器上设置不同的 Scala 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆