Scala安装指南

Scala安装指南

确认Java已经安装

1
java -version

下载最新版本的Scala

1
http://www.scala-lang.org/downloads

安装

设置环境变量

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

测试是否正常

查看当前scala的版本

1
scala -version

进入交互shell

1
scala

Hello, world!

测试例子使用代码

1
2
3
4
5
object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world!")
  }
}

交互方式输入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
> scala
This is a Scala shell.
Type in expressions to have them evaluated.
Type :help for more information.
scala> object HelloWorld {
    |   def main(args: Array[String]) {
    |     println("Hello, world!")
    |   }
    | }
defined module HelloWorld
scala> HelloWorld.main(null)
Hello, world!
scala>:q
>

编译方式,编译

1
> scalac HelloWorld.scala

然后运行

1
> scala HelloWorld

END.