hsenv を使って、 ghc のサンドボックス環境を作る手順をメモ。
インストール
$ cabal update
$ cabal install hsenv
サンドボックス環境の作成
# サンドボックス環境用のディレクトリ作成
$ mkdir -p ~/.haskell/hsenv/env-test-7.6.3
$ cd ~/.haskell/hsenv/env-test-7.6.3
# サンドボックス環境作成
$ hsenv
Creating Virtual Haskell directory structure
Installing GHC
Initializing GHC Package database at /Users/hyone/.haskell/hsenv/env-test-7.6.3/.hsenv/ghc_pkg_db
Copying necessary packages from original GHC package database
Failed to copy optional package ghc-binary from system's GHC:
/usr/local/bin/ghc-pkg process failed with status 1
Using user-wide (~/.cabal/packages) Hackage download cache directory
Installing cabal config at /Users/hyone/.haskell/hsenv/env-test-7.6.3/.hsenv/cabal/config
Installing activate script
Installing cabal wrapper using /Users/hyone/.haskell/hsenv/env-test-7.6.3/.hsenv/cabal/config at /Users/hyone/.haskell/hsenv/env-test-7.6.3/.hsenv/bin/cabal
Skipping 'cabal update' step, Hackage download cache already downloaded
to ~/.cabal/packages/. You can update it manually with 'cabal update'
(from inside or outside the virtual environment).
To activate the new environment use 'source .hsenv/bin/activate'
サンドボックス環境へ切り替え
# システム環境の cabal のパスを確認
$ which cabal
/usr/local/bin/cabal
サンドボックス環境へ切り替え
$ source .hsenv/bin/activate
Activating Virtual Haskell Environment (at /Users/hyone/.haskell/hsenv/env-test-7.6.3).
Use regular Haskell tools (ghc, ghci, ghc-pkg, cabal) to manage your Haskell environment.
To exit from this virtual environment, enter command 'deactivate_hsenv'.
[hsenv]
# cabal のパスがサンドボックス環境のものになっていることを確認
$ which cabal
/Users/hyone/.haskell/hsenv/env-test-7.6.3/.hsenv/bin/cabal
# パッケージリストも同様に確認
$ ghc-pkg list
/Users/hyone/.haskell/hsenv/env-test-7.6.3/.hsenv/ghc_pkg_db
Cabal-1.16.0
array-0.4.0.1
base-4.6.0.1
...
# サンドボックス環境に url モジュールをインストール
$ cabal install url
$ ghc-pkg list | grep url
url-2.1.3
サンドボックス環境から脱出
$ deactivate_hsenv
Deactivating Virtual Haskell Environment (at /Users/hyone/.haskell/hsenv/env-test-7.6.3).
Restoring previous environment settings.
# システム環境の cabal を差しているか確認
$ which cabal
/usr/local/bin/cabal
# システム環境には url モジュールがインストールされていないことを確認
$ ghc-pkg list | grep url
また、 hsenv では、仮想環境作成時に、ダウンロードしてきた ghc のバイナリ配布物を指定することで、独自のバージョンの ghc を使うことができる。
$ curl -O http://www.haskell.org/ghc/dist/7.6.2/ghc-7.6.2-x86_64-apple-darwin.tar.bz2
$ mkdir -p ~/.haskell/hsenv/env-test-7.6.2
$ cd ~/.haskell/hsenv/env-test-7.6.2
$ hsenv --ghc=$HOME/Downloads/ghc-7.6.2-x86_64-apple-darwin.tar.bz2
Creating Virtual Haskell directory structure
Installing GHC
Installing GHC from /Users/hyone/Downloads/ghc-7.6.2-x86_64-apple-darwin.tar.bz2
Initializing GHC Package database at /Users/hyone/.haskell/hsenv/env-test-7.6.2/.hsenv/ghc_pkg_db
Copying necessary packages from original GHC package database
Using user-wide (~/.cabal/packages) Hackage download cache directory
Installing cabal config at /Users/hyone/.haskell/hsenv/env-test-7.6.2/.hsenv/cabal/config
Installing activate script
Installing cabal wrapper using /Users/hyone/.haskell/hsenv/env-test-7.6.2/.hsenv/cabal/config at /Users/hyone/.haskell/hsenv/env-test-7.6.2/.hsenv/bin/cabalSkipping 'cabal update' step, Hackage download cache already downloaded
to ~/.cabal/packages/. You can update it manually with 'cabal update'
(from inside or outside the virtual environment).
To activate the new environment use 'source .hsenv/bin/activate'
$ source .hsenv/bin/activate
$ which ghc
/Users/hyone/.haskell/hsenv/env-test-7.6.2/.hsenv/bin/ghc
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.6.2
$ deactivate_hsenv
Deactivating Virtual Haskell Environment (at /Users/hyone/.haskell/hsenv/env-test-7.6.2).
Restoring previous environment settings.
$ which ghc
/usr/local/bin/ghc
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.6.3