Gentoo に Scala をインストールする

注: インストール前に必ず Java をインストールしておくこと

Java をインストールしておかないと、Scala 起動時に下記のようなエラーが発生する。

# which scala
/usr/bin/scala

# scala -version
Traceback (most recent call last):
  File "/usr/bin/gjl", line 300, in <module>
    vm = get_vm(pkg)
  File "/usr/bin/gjl", line 205, in get_vm
    if verman.version_satisfies( needed, manager.get_active_vm()):
  File "//usr/lib/python2.5/site-packages/java_config_2/EnvironmentManager.py", line 127, in get_active_vm
    self.load_active_vm()
  File "//usr/lib/python2.5/site-packages/java_config_2/EnvironmentManager.py", line 120, in load_active_vm
    raise InvalidVMError("Unable to determine valid vm. Please see http://www.gentoo.org/doc/en/java.xml#doc_chap4")
java_config_2.Errors.InvalidVMError: Unable to determine valid vm. Please see http://www.gentoo.org/doc/en/java.xml#doc_chap4
Couldn't get needed information

この時、Scala の依存パッケージとしてインストールされる Java を動作させてみると、

# java -version
basename: missing operand
Try `basename --help' for more information.
* Home for VM '' does not exist:
* Invalid System VM:

というエラーが発生する。
このようなエラーが発生した Scala をアンインストールするには、

# emerge --unmerge scala

とする。

Scala が Portarge に登録されている状況を確認する

# emerge -pv dev-lang/scala

These are the packages that would be merged, in order:

Calculating dependencies... done!

!!! All ebuilds that could satisfy "dev-lang/scala" have been masked.
!!! One of the following masked packages is required to complete your request:
- dev-lang/scala-2.7.5 (masked by: ~x86 keyword)
- dev-lang/scala-2.7.4-r1 (masked by: ~x86 keyword)
- dev-lang/scala-2.7.4 (masked by: ~x86 keyword)
- dev-lang/scala-2.7.3-r1 (masked by: ~x86 keyword)
- dev-lang/scala-2.7.3 (masked by: ~x86 keyword)
- dev-lang/scala-2.7.2 (masked by: ~x86 keyword)

For more information, see the MASKED PACKAGES section in the emerge
man page or refer to the Gentoo Handbook.

Scala は masked の状態であり、複数のバージョンの Scala がインストールできる状態になっている。また、最新版の Scala をインストールできる状態にあることがわかる。

Scalaebuild を確認する

# ls -l /usr/portage/dev-lang/scala/
total 40
-rw-r--r-- 1 root    root    3234 Jun  5 18:05 ChangeLog
-rw-r--r-- 1 root    root    3866 Jun  5 18:05 Manifest
drwxr-xr-x 2 portage portage 4096 Feb 11  2009 files
-rw-r--r-- 1 portage portage  317 Aug 23  2008 metadata.xml
-rw-r--r-- 1 root    root    3279 Apr  5 17:08 scala-2.7.2.ebuild
-rw-r--r-- 1 portage portage 3263 Feb 15  2009 scala-2.7.3-r1.ebuild
-rw-r--r-- 1 root    root    3386 Apr  5 17:08 scala-2.7.3.ebuild
-rw-r--r-- 1 root    root    3180 May  1 16:44 scala-2.7.4-r1.ebuild
-rw-r--r-- 1 root    root    3296 May  1 04:29 scala-2.7.4.ebuild
-rw-r--r-- 1 root    root    3160 Jun  5 17:45 scala-2.7.5.ebuild

masked の対象外にして、インストールする Scala のバージョンを明示的に指定する

/etc/portage/package.unmask にインストールする Scala のバージョンを記述する。

# vi /etc/portage/package.unmask
>=dev-lang/scala-2.7.5

Scala をインストールする

まずはパッケージの依存状況も含めて、インストールの設定内容を確認する。

# ACCEPT_KEYWORDS="~x86" emerge dev-lang/scala -vp

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N    ] app-portage/portage-utils-0.2  86 kB
[ebuild  N    ] media-libs/giflib-4.1.6-r1  USE="-X -rle" 495 kB
[ebuild  N    ] media-libs/jpeg-7  950 kB
[ebuild  N    ] dev-python/pyxml-0.8.4-r2  USE="-doc -examples" 718 kB
[ebuild  N    ] dev-java/javatoolkit-0.3.0-r3  17 kB
[ebuild  N    ] app-arch/unzip-6.0-r1  USE="bzip2 unicode" 1,345 kB
[ebuild  N    ] dev-java/java-config-wrapper-0.16  8 kB
[ebuild  N    ] media-libs/libpng-1.2.38  514 kB
[ebuild  N    ] dev-java/java-config-2.1.8-r1  56 kB
[ebuild  N    ] dev-java/icedtea6-bin-1.4.1  USE="-X -alsa -doc -examples -nsplugin -source" 34,990 kB
[ebuild  N    ] virtual/jdk-1.6.0  0 kB
[ebuild  N    ] dev-java/ant-core-1.7.1-r4  USE="-doc -source" 6,828 kB
[ebuild  N    ] virtual/jre-1.6.0  0 kB
[ebuild  N    ] dev-java/jakarta-oro-2.0.8-r2  USE="-doc -examples -source" 338 kB
[ebuild  N    ] dev-java/commons-logging-1.1.1  USE="-avalon-framework -avalon-logkit -doc -log4j -servletapi -source -test" 187 kB
[ebuild  N    ] dev-java/xml-commons-external-1.3.04  USE="-doc -source" 645 kB
[ebuild  N    ] dev-java/ant-nodeps-1.7.1  0 kB
[ebuild  N    ] dev-java/jline-0.9.94  USE="-doc -source -test" 754 kB
[ebuild  N    ] dev-java/bcel-5.2  USE="-doc -source" 256 kB
[ebuild  N    ] dev-java/commons-cli-1.2  USE="-doc -source -test" 67 kB
[ebuild  N    ] dev-java/commons-collections-3.2.1  USE="-doc -source -test -test-framework" 596 kB
[ebuild  N    ] dev-java/jzlib-1.0.7-r1  USE="-doc -source" 50 kB
[ebuild  N    ] dev-java/commons-codec-1.3-r2  USE="-doc -source -test" 87 kB
[ebuild  N    ] dev-java/xml-commons-resolver-1.2  USE="-doc -source" 257 kB
[ebuild  N    ] dev-java/xjavac-20041208-r5  2 kB
[ebuild  N    ] dev-java/commons-httpclient-3.1  USE="-doc -examples -source -test" 1,839 kB
[ebuild  N    ] dev-java/jsch-0.1.41  USE="zlib -doc -examples -source" 276 kB
[ebuild  N    ] dev-java/commons-net-1.4.1-r1  USE="-doc -examples -source" 224 kB
[ebuild  N    ] dev-java/xalan-serializer-2.7.1  USE="-doc -source" 6,138 kB
[ebuild  N    ] dev-java/commons-vfs-1.0  USE="-doc -source" 273 kB
[ebuild  N    ] dev-java/xerces-2.9.1  USE="-doc -examples -source" 1,672 kB
[ebuild  N    ] dev-java/ant-ivy-2.0.0  USE="-doc -examples -source -test" 2,196 kB
[ebuild  N    ] dev-java/ant-ivy-1.4.1  USE="-doc -examples -source -test" 735 kB
[ebuild  N    ] dev-java/ant-contrib-1.0_beta3  USE="-doc -source" 3,221 kB
[ebuild  N    ] dev-lang/scala-2.7.5  USE="-binary -doc -emacs -examples -source" 28,767 kB

Total: 35 packages (35 new), Size of downloads: 94,570 kB

インストールを実行する。

# ACCEPT_KEYWORDS="~x86" emerge dev-lang/scala

長い時間をかけた後に、コンパイル終了後にエラーが発生…。

>>>  '/var/tmp/portage/dev-lang/scala-2.7.5/temp/build.log'

 * Messages for package dev-lang/scala-2.7.5:

 * This package can fail to build with memory allocation errors in some cases.
 * If you are unable to build from sources, please try USE=binary
 * for this package. See bug #181390 for more information.
 * Don't have at least 512MBytes RAM
 * Bad things may happen! You may abort the build by pressing ctrl+c in
 * the next 15 seconds.
 *
 *
 * ERROR: dev-lang/scala-2.7.5 failed.
 * Call stack:
 *               ebuild.sh, line   49:  Called src_compile
 *             environment, line 4272:  Called eant 'all.clean' 'dist.done'
 *             environment, line  982:  Called die
 * The specific snippet of code:
 *       ant ${antflags} "${@}" || die "eant failed"
 *  The die message:
 *   eant failed
 *
 * If you need support, post the topmost build error, and the call stack if relevant.
 * A complete build log is located at '/var/tmp/portage/dev-lang/scala-2.7.5/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/dev-lang/scala-2.7.5/temp/environment'.
 *

 * IMPORTANT: 1 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.

エラーログを見ると、メモリーが足りないために、発生したようだ。解決策として、コンパイル済みのバイナリをインストールしろとのこと。

 * This package can fail to build with memory allocation errors in some cases.
 * If you are unable to build from sources, please try USE=binary
 * for this package. See bug #181390 for more information.
 * Don't have at least 512MBytes RAM

ということで、

# ACCEPT_KEYWORDS="~x86" USE="binary" emerge dev-lang/scala
# scala -version
Welcome to Scala version 2.7.5.r0-b20090605191508 (Java HotSpot(TM) Client VM, Java 1.6.0_15).
Type in expressions to have them evaluated.
Type :help for more information.

でインストールは完了。