Scala installation


Scala language can run on Window, Linux, Unix, Mac OS X and other systems.

Scala is based on Java and uses a large number of Java class libraries and variables. You must install Java (>1.5 version) before using Scala.


Installing Scala on Mac OS Environment variables and JDK bin directory.

We can use the following command to check whether 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 whether the Java compiler is installed. Enter the following command to view:

$ javac -version
javac 1.8.0_31
$

If it is still installed, you can refer to our Java development environment configuration.

Next, we can download the Scala binary package from the Scala official website address http://www.scala-lang.org/downloads. In this tutorial we will download the

2.11.7

version, as follows As shown in the picture:

Unzip the file package and move it to /usr/local/share:

mv scala-2.11.7 scala                   # 重命名 Scala 目录
mv /download/scalapath /usr/local/share # 下载目录需要按你实际的下载路径
Scala-download.jpgModify the environment variable, if not Administrators can use sudo to enter administrator privileges, modify the configuration file profile:

vim /etc/profile

或

sudo vim /etc/profile

and add:

export PATH="$PATH:/usr/local/share/scala/bin"

:wq! at the end of the file. Save and exit, restart the terminal, execute the scala command, and output the following Information, indicating 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:

During compilation, if there are Chinese garbled characters, garbled characters will appear. See the solution: Scala Chinese garbled characters solution

Install Scala on window

Step one: Java settings

The detection method has been explained previously and will not be described here.

If it is still not installed, you can refer to our Java development environment configuration.

Next, we can download the Scala binary package from the Scala official website address http://www.scala-lang.org/downloads. In this tutorial we will download the

2.11.7

version, as follows As shown in the picture:

After downloading, double-click the msi file and install it step by step. You can use the default installation directory during the installation process.

Scala-download.jpgAfter installing scala, the system will automatically prompt you to click finish to complete the installation.

Right-click My Computer, click "Properties", and enter the page as shown in the picture. Next, start configuring environment variables, right-click [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 variable value field: D:\Program Files\scala is the installation directory of scala , it varies according to personal circumstances. If it is installed on the C drive, just change "D" to "C".

scala2.jpg

Set Path variable: Find "Path" under system variables as shown in the figure, click Edit. Add the following path at the front of the "Variable Value" column: %SCALA_HOME%\bin;%SCALA_HOME%\jre\bin;

Note: the semicolon after ; Don’t miss it.

scala3.jpg

Set the Classpath variable: Find "Classpath" under the system variables as shown in the figure, click Edit, if not, click "New":

  • "Variable name": ClassPath

  • "Variable value": .;%SCALA_HOME%\bin;%SCALA_HOME%\lib\dt.jar;%SCALA_HOME %\lib\tools.jar.;

Note: Don’t miss the .; at the front of "variable value". Finally click OK.

scala4.jpg

#Check whether the environment variables are set: call up "cmd" to check. Click [Start], enter cmd in the input box, then "Enter", enter scala, and then press Enter. If the environment variables are set ok, you should be able to see this information.

scala5.jpg

The following lists the directories placed by different systems (can be used as a reference):

System environmentVariablesValue (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