简体   繁体   English

如何安装scala 2.12

[英]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.有多个二进制不兼容的 scala 2 版本,但是文档说安装是通过 IDE 或 SBT。

DOWNLOAD SCALA 2下载 SCALA 2

Then, install Scala:...either by installing an IDE such as IntelliJ, or sbt, Scala's build tool.然后,安装 Scala:...通过安装 IDE(例如 IntelliJ)或 sbt(Scala 的构建工具)。

Spark 3 needs Scala 2.12. Spark 3需要 Scala 2.12。

Spark 3.1.2 uses Scala 2.12. Spark 3.1.2 使用 Scala 2.12。 You will need to use a compatible Scala version (2.12.x).您将需要使用兼容的 Scala 版本 (2.12.x)。

Then how can we make sure the scala version is 2.12 if we install sbt?那么如果我们安装 sbt,我们如何确保 scala 版本是 2.12?

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"?还是文档不准确,应该是“要使用特定版本的scala,需要自己下载特定的scala版本”?


Updates更新

As per the answer by mario-galic , in ONE-CLICK INSTALL FOR SCALA it is said:根据mario-galic的回答,在 SCALA 的一键安装中说:

Installing Scala has always been a task more challenging than necessary, with the potential to drive away beginners.安装 Scala 一直是一项比必要的更具挑战性的任务,有可能赶走初学者。 Should I install Scala itself?我应该自己安装 Scala 吗? sbt? sbt? Some other build tools?其他一些构建工具? What about a better REPL like Ammonite?像 Ammonite 这样更好的 REPL 怎么样? Oh and before all that I need to install Java?哦,在我需要安装 Java 之前?

To solve this problem, the Scala Center contracted Alexandre Archambault in January 2020 to add a one-click install of Scala through coursier.为了解决这个问题,Scala 中心于 2020 年 1 月与 Alexandre Archambault 签约,通过 coursier 增加一键安装 Scala。 For example, on Linux, all we now need is:例如,在 Linux 上,我们现在需要的是:
$ 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. Scala 版本在build.sbt文件中指定,因此 SBT 将根据需要下载适当版本的 Z3012DCFF1477E1FEAAB817645ZC7。

I personally use SDKMAN!我个人使用SDKMAN! to install Java and then SBT.安装 Java 然后 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系统范围的安装最终会在PATH上的某个位置,例如

/usr/local/bin/scala

and can be installed in various ways, personally I recommend coursier one-click install for Scala并且可以多种方式安装,个人推荐Scala的coursier一键安装

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.项目特定版本由scalaVersion sbt 设置指定,该设置将 Scala 下载到 coursier 缓存位置。 To see the Scala version and location used by the particular project try show scalaInstance which要查看特定项目使用的 Scala 版本和位置,请尝试show scalaInstance

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 . Scala 在次要版本中应该是二进制兼容的,因此 Spark 3 或针对任何 Scala 2.12.x 版本构建的任何其他软件应该与任何其他 Scala 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.请注意,内部编译器 API 不保证二进制兼容性,因此例如在发布编译器插件时,最佳做法是针对完整的特定 Scala 版本发布它。 For example notice how kind-projector compiler plugin is published against full Scala version 2.13.6例如注意 kind-projector 编译器插件是如何针对完整的 Scala 版本2.13.6发布的

https://repo1.maven.org/maven2/org/typelevel/kind-projector_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而 scala-cats 应用程序级库针对任何 Scala 2.13.x版本发布

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

Similarly spark is published against any Scala 2.12.x version同样,火花针对任何 Scala 2.12.x版本发布

https://repo1.maven.org/maven2/org/apache/spark/spark-core_2.12/ 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-runners放在PATH上,然后可以通过--scala-version参数启动不同的版本

scala --scala-version 2.12.14

Using coursier or scala-runners you can even switch JDK quickly via -C--jvm for example例如,使用 coursier 或 scala-runners,您甚至可以通过-C--jvm快速切换 JDK

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.对于一个项目,应该不需要手动下载 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 . sbt 直接或间接通过 IDE 将为您下载幕后的所有依赖项,因此唯一需要指定的是 sbt 设置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 . 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.在执行pipenv shellpipenv install之后,您最终会得到项目特定的 shell 环境,其中项目特定的 Python 版本和依赖项。 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. sbt 类似地下载项目特定的 Scala 版本和基于build.sbt的依赖项,尽管它不需要锁定文件或修改您的 Z2591C98B70119B5E2944 环境。

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

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