English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Scala language can run on Windows, Linux, Unix, Mac OS X and other systems.
Scala is based on Java, extensively using Java's class libraries and variables, and Java must be installed before using Scala (>1.5version).
Ensure that JDK is already installed locally 1.5 The above version, and set the JAVA_HOME environment variable and the JDK's bin directory.
We can use the following command to check if Java is installed:
$ java -version java version "1.8.0_31" Java TM SE Runtime Environment (build 1.8.0_31-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode) $
Next, we can check if the Java compiler has been installed. Enter the following command to view:
$ javac -version javac 1.8.0_31 $
If it has not been installed yet, you can refer to ourJava Development Environment Configuration.
Next, we can download from the Scala official website address http://www.scala-lang.org/downloads Download the Scala binary package, in this tutorial we will download 2.11.7Version, as shown in the figure below:
Unzip the file package and you can move it to/usr/local/share under:
mv scala-2.11.7 scala # Rename the Scala directory mv /download/scalapath /usr/local/share # The download directory needs to be according to your actual download path
Modify the environment variables, if not an administrator, you can use sudo to enter administrator privileges and modify the configuration file profile:
vim /etc/profile or sudo vim /etc/profile
Add to the end of the file:
export PATH="$PATH:/usr/local/share/scala/bin"
:wq! Save and exit, restart the terminal, and execute the scala command to output the following information, indicating a successful installation:
$ scala Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_31). Type in expressions to have them evaluated. Type: help for more information.
Note:When compiling, if there are Chinese characters, they will appear in garbled code, see the solution for details:Scala Chinese Character Encoding Solution
detection methods have been described in the previous text and will not be described here.
If it has not been installed yet, you can refer to ourJava Development Environment Configuration.
Next, we can download from the Scala official website address http://www.scala-lang.org/downloads Download the Scala binary package (at the bottom of the page), in this tutorial we will download 2.11.7Version, as shown in the figure below:
After downloading, double-click the msi file, follow the steps to install, and you can use the default installation directory during the installation process.
After installing Scala, the system will automatically prompt you to click finish, completing the installation.
Right-click on My Computer, click "Properties", and enter the page as shown in the figure. Below, we will start configuring the environment variables, right-click on [My Computer]--[Properties]--[Advanced System Settings]--[Environment Variables], as shown in the figure:
Set the SCALA_HOME variable: Click New, and enter in the variable name field:SCALA_HOME: Enter the value for the variable column:D:\Program Files(x86)\scala This is the Scala installation directory, which may vary depending on personal circumstances. If installed on the C drive, change D to C.
Set Path Variable: Find the "Path" under System Variables as shown in the figure, click Edit. Add the following path at the beginning of the "Variable Value" field: %SCALA_HOME%\bin;%SCALA_HOME%\jre\bin;
Note:The semicolon after ; Do not miss.
Set Classpath Variable: Find the "Classpath" under System Variables as shown in the figure, click Edit. If there is none, click "New":
"Variable Name":ClassPath
"Variable Value":.;%SCALA_HOME%\bin;%SCALA_HOME%\lib\dt.jar;%SCALA_HOME%\lib\tools.jar.;
Note:Do not miss the .; at the beginning of the "Variable Value". Click OK at the end.
Check if the environment variables are set correctly: Bring up "cmd" to check. Click [Start], enter cmd in the input box, then press Enter, enter scala, and then press Enter. If the environment variables are set ok, you should see this information.
The following lists the directories placed in different systems (for reference):
System Environment | Variable | Value (Example) |
---|---|---|
Unix | $SCALA_HOME | /usr/local/share/scala |
$PATH | $PATH:$SCALA_HOME/bin | |
Windows | %SCALA_HOME% | c:\Progra~1\Scala |
%PATH% | %PATH%;%SCALA_HOME%\bin |