简体   繁体   中英

How to install scala 2.12

There are multiple binary incompatible scala 2 versions, however the document says the installation is either via IDE or SBT.

DOWNLOAD SCALA 2

Then, install Scala:...either by installing an IDE such as IntelliJ, or sbt, Scala's build tool.

Spark 3 needs Scala 2.12.

Spark 3.1.2 uses Scala 2.12. You will need to use a compatible Scala version (2.12.x).

Then how can we make sure the scala version is 2.12 if we install sbt?

Or the documentation is not accurate and it should be "to use specific version of scala, need to download specific scala version on your own"?


Updates

As per the answer by mario-galic , in ONE-CLICK INSTALL FOR SCALA it is said:

Installing Scala has always been a task more challenging than necessary, with the potential to drive away beginners. Should I install Scala itself? sbt? Some other build tools? What about a better REPL like Ammonite? Oh and before all that I need to install Java?

To solve this problem, the Scala Center contracted Alexandre Archambault in January 2020 to add a one-click install of Scala through coursier. For example, on Linux, all we now need is:
$ curl -Lo cs https://git.io/coursier-cli-linux && chmod +x cs &&./cs setup

The Scala version is specified in the build.sbt file so SBT will download the appropriate version of Scala as necessary.

I personally use SDKMAN! to install Java and then SBT.

The key concept to understand is the difference between system-wide installation and project-specific version. System-wide installation ends up somewhere on the PATH like

/usr/local/bin/scala

and can be installed in various ways, personally I recommend coursier one-click install for Scala

curl -Lo cs https://git.io/coursier-cli-linux && chmod +x cs && ./cs setup

Project-specific version is specified by scalaVersion sbt settings which downloads Scala to coursier cache location. To see the Scala version and location used by the particular project try show scalaInstance which

inspect scalaInstance
[info] Task: sbt.internal.inc.ScalaInstance
[info] Description:
[info]  Defines the Scala instance to use for compilation, running, and testing.

Scala should be binary compatible within minor version so Spark 3 or any other software built against any Scala 2.12.x version should work with any other Scala 2.12.x version where we have major.minor.patch . Note binary compatibility is not guaranteed for internal compiler APIs, so for example when publishing compiler plugins the best practice is to publish it against full specific Scala version. For example notice how kind-projector compiler plugin is published against full Scala version 2.13.6

https://repo1.maven.org/maven2/org/typelevel/kind-projector_2.13.6/

whilst scala-cats application-level library is published against any Scala 2.13.x version

https://repo1.maven.org/maven2/org/typelevel/cats-core_2.13/

Similarly spark is published against any Scala 2.12.x version

https://repo1.maven.org/maven2/org/apache/spark/spark-core_2.12/

Regarding system-wide installation one trick I do for quick switching of versions is to put scala-runners on the PATH and then different versions can be launched via --scala-version argument

scala --scala-version 2.12.14

Using coursier or scala-runners you can even switch JDK quickly via -C--jvm for example

scala --scala-version 2.12.14 -C--jvm=11

For a project, there should be no need to download manually a specific version of Scala. sbt either directly or indirectly via an IDE will download all the dependencies behind the scenes for you, so the only thing to specify is sbt setting scalaVersion .

Using Python as analogy to Scala, and Pipenv as anology to sbt, then python_version in Pipfile is similar to scalaVersion in build.sbt . After executing pipenv shell and pipenv install you end up with project-specific shell environment with project specific Python version and dependencies. sbt similarly downloads project specific Scala version and dependencies based of build.sbt although it has no need for lock files or for modifying your shell environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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