📅  最后修改于: 2020-11-02 04:26:03             🧑  作者: Mango
Scala可以安装在任何基于UNIX或Windows的系统上。在机器上开始安装Scala之前,必须在计算机上安装Java 1.8或更高版本。
请按照下面给出的步骤安装Scala。
首先,您需要在系统上安装Java软件开发套件(SDK)。要验证这一点,请根据所使用的平台执行以下两个命令之一。
如果Java安装正确完成,则它将显示Java安装的当前版本和规范。下表中给出了示例输出。
Platform | Command | Sample Output |
---|---|---|
Windows |
Open Command Console and type − \>java -version |
Java version “1.8.0_31” Java (TM) SE Run Time Environment (build 1.8.0_31-b31) Java Hotspot (TM) 64-bit Server VM (build 25.31-b07, mixed mode) |
Linux |
Open Command terminal and type − $java -version |
Java version “1.8.0_31” Open JDK Runtime Environment (rhel-2.8.10.4.el6_4-x86_64) Open JDK 64-Bit Server VM (build 25.31-b07, mixed mode) |
我们假定本教程的读者已在其系统上安装了Java SDK版本1.8.0_31。
如果您没有Java SDK,请从https://www.oracle.com/technetwork/java/javase/downloads/index.html下载其最新版本并进行安装。
将环境变量JAVA_HOME设置为指向计算机上Java安装位置的基本目录位置。例如,
Sr.No | Platform & Description |
---|---|
1 |
Windows Set JAVA_HOME to C:\ProgramFiles\java\jdk1.8.0_31 |
2 |
Linux Export JAVA_HOME=/usr/local/java-current |
将Java编译器位置的完整路径追加到系统路径。
Sr.No | Platform & Description |
---|---|
1 |
Windows Append the String “C:\Program Files\Java\jdk1.8.0_31\bin” to the end of the system variable PATH. |
2 |
Linux Export PATH=$PATH:$JAVA_HOME/bin/ |
如上所述,从命令提示符处执行命令java -version 。
您可以从www.scala-lang.org/downloads下载Scala。在撰写本教程时,我下载了“ scala-2.13.1-installer.jar”。确保您具有管理员权限才能继续。现在,在命令提示符处执行以下命令-
Platform | Command & Output | Description |
---|---|---|
Windows |
\>java -jar scala-2.13.1-installer.jar\> |
This command will display an installation wizard, which will guide you to install Scala on your windows machine. During installation, it will ask for license agreement, simply accept it and further it will ask a path where Scala will be installed. I selected default given path “C:\Program Files\Scala”, you can select a suitable path as per your convenience. |
Linux |
Command − $java -jar scala-2.13.1-installer.jar Output − Welcome to the installation of Scala 2.13.1! The homepage is at − http://Scala-lang.org/ press 1 to continue, 2 to quit, 3 to redisplay 1………………………………………… [ Starting to unpack ] [ Processing package: Software Package Installation (1/1) ] [ Unpacking finished ] [ Console installation done ] |
During installation, it will ask for license agreement, to accept it type 1 and it will ask a path where Scala will be installed. I entered /usr/local/share, you can select a suitable path as per your convenience. |
最后,打开一个新的命令提示符,然后键入Scala -version并按Enter。您应该看到以下内容-
Platform | Command | Output |
---|---|---|
Windows |
\>scala -version |
Scala code runner version 2.13.1 — Copyright 2002-2019, LAMP/EPFL and Lightbend, Inc. |
Linux |
$scala -version |
Scala code runner version 2.13.1 — Copyright 2002-2019, LAMP/EPFL and Lightbend, Inc.tut |