Scalaに入門したい。#1 インストール

・インストール

  1. ダウンロード
  2. Download | The Scala Programming Language


    上のページから使っているOSに合わせてダウンロードする。

    Stableは2.7.7だったが、すでにインストールしてあったので2.8.0を落としてきた。

    ちなみにうちの環境はOSX 10.5.8だった。


  3. インストール
  4. 落としてきたファイルを展開して中をみると

    [kousaka]% tar -xf scala-2.8.0.RC1.tgz
    [kousaka]% cd scala-2.8.0.RC1
    [kousaka]% cd doc
    [kousaka]% cat README
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    Unix Installation
    -----------------
    
    Untar the archive. All Scala tools are located in the "bin" directory.
    Adding that directory to the PATH variable will make the Scala commands
    directly accessible.
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    とあるので「/scalaほにゃほにゃ/bin」にPATHを通せばいいらしい。

    それで終わり!!なんと簡単なっ!!



  5. テスト
  6. READMEの中にテストについて書いてあったのでやってみる。

    You may test the distribution by running the following commands:
    
    $ ./bin/sbaz install scala-devel-docs
    $ ./bin/scalac doc/scala-devel-docs/examples/sort.scala
    $ ./bin/scala examples.sort
    [6,2,8,5,1]
    [1,2,5,6,8]
    $ ./bin/scala
    scala> examples.sort.main(null)
    [6,2,8,5,1]
    [1,2,5,6,8]
    scala>:quit
    $

    この通りに試してみるべ。

    [kousaka]% ./bin/sbaz install scala-devel-docs       [j06027:~/scala-2.8.0.RC1]
    planning to install: scala-devel-docs/2.8.0.RC1
    Installing...
    Downloading: http://www.scala-lang.org/downloads/packages/scala-devel-docs-2.8.0.RC1.sbp
    13.08M/13.08M Done  #scala/docにscala-develdocs/ができる
    [kousaka]% ./bin/scalac doc/scala-devel-docs/examples/sort.scala                [j06027:~/Desktop/scala-2.8.0.RC1]    #コンパイルされる
    [kousaka]% ./bin/scala examples.sort                [j06027:~/scala-2.8.0.RC1]
    [6,2,8,5,1]
    [1,2,5,6,8]
    [kousaka]% ./bin/scala                              [j06027:~/scala-2.8.0.RC1]
    Welcome to Scala version 2.8.0.RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_17).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala> examples.sort.main(null)
    [6,2,8,5,1]
    [1,2,5,6,8]
    
    scala> :exit
    Unknown command.  Type :help for help.
    
    scala> :quit
    

    おういえ!!

    簡単ですねん。



  7. PATH通す
  8. その前に、homeディレクトリに置いとくのは邪魔なのでどっかに移動させる。

    [kousaka]% sudo mv scala-2.8.0.RC1 /usr/                             [j06027:~]

    とかで、いいんじゃね?

    それでシェルの環境設定ファイルにPATHを追加しておわりです。

    zshを使っているので~/.zshrcに

    path=( $path /usr/scala-2.8.0.RC1/bin )

    最後にホームからscalaインタプリタを起動してみる

    [kousaka]%scala                                                              [j06027:~]
    Welcome to Scala version 2.8.0.RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_17).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala>
  9. まとめ
    • インストールは簡単。落としてきてPATH通すだけ
    • JVMは1.5以上で動くらしいっす

第二回へ;Scalaに入門したい。#2 変数と関数 - 風の谷の備忘録