Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quickly switching Scala versions from CLI

nvm (Node Version Manager) enables quick selection of alternative Node version to work with. Does Scala have a similar way of quickly switching different versions in the current shell? For example, say I want to start REPL with 2.12.10, then executing something something like

scala use 2.12.10

would greet with

Welcome to Scala 2.12.10 (OpenJDK 64-Bit Server VM, Java 1.8.0_202).
Type in expressions for evaluation. Or try :help.

Note the question is not about SBT via scalaVersion, but using scala command directly from the command line.

like image 893
Mario Galic Avatar asked Sep 08 '25 00:09

Mario Galic


2 Answers

Alternatively to scala-runners, there's also sdkman, which is a more general tool but also supports scala. For example, command:

sdk use scala 2.12.10

sets scala to 2.12.10 for current shell session.

like image 185
Krzysztof Atłasik Avatar answered Sep 09 '25 14:09

Krzysztof Atłasik


dwijnand/scala-runners

An alternative implementation of the Scala distribution's runners: scala, scalac, scaladoc, and scalap (no fsc). They are implemented as thin shell scripts around Coursier's coursier launch to add some Scala runners-specific (power) options.

provide a quick way of starting different versions

scala --scala-version 2.12.10

and even development versions from

https://scala-ci.typesafe.com/artifactory/scala-integration
https://scala-ci.typesafe.com/artifactory/scala-pr-validation-snapshots

for example

scala --scala-version 2.13.2-bin-81d1da3

or particular pull request

scala --scala-pr 8960
like image 45
Mario Galic Avatar answered Sep 09 '25 14:09

Mario Galic