无法在 haskell 平台上使用 cabal 初始化沙箱

Not able to initialize sandbox using cabal on haskell platform

我已经完成了以下步骤来安装 cabal 。我已经使用 sudo apt-get install haskell-platform

安装了 haskell 平台

http://coldwa.st/e/blog/2013-08-20-Cabal-sandbox.html

Building Cabal from git
Assuming you already have a previous version of cabal installed:

$ git clone git://github.com/haskell/cabal.git /path/to/cabal
$ cd /path/to/cabal
$ cabal install Cabal/ cabal-install/

然而,当我尝试初始化沙箱时,它会抛出如下错误。

vagrant@vagrant-ubuntu-trusty-32:/usr/lib/haskell-packages$ cabal sandbox --help
cabal: unrecognised command: sandbox (try --help)

添加更多详细信息:

vagrant@vagrant-ubuntu-trusty-32:/usr/lib/haskell-packages$ cabal --version
cabal-install version 1.16.0.2
using version 1.16.0 of the Cabal library
vagrant@vagrant-ubuntu-trusty-32:/usr/lib/haskell-packages$ which cabal
/home/vagrant/.cabal/bin/cabal



vagrant@vagrant-ubuntu-trusty-32:/usr/lib/haskell-packages$ cabal --help
This program is the command line interface to the Haskell Cabal infrastructure.
See http://www.haskell.org/cabal/ for more information.

Usage: cabal COMMAND [FLAGS]
   or: cabal [GLOBAL FLAGS]

Global flags:
 -h --help            Show this help text
 -V --version         Print version information
    --numeric-version Print just the version number

Commands:
  install      Installs a list of packages.
  update       Updates list of known packages
  list         List packages matching a search string.
  info         Display detailed information about a particular package.
  fetch        Downloads packages for later installation.
  unpack       Unpacks packages for user inspection.
  check        Check the package for common mistakes
  sdist        Generate a source distribution file (.tar.gz).
  upload       Uploads source packages to Hackage
  report       Upload build reports to a remote server.
  init         Interactively create a .cabal file.
  configure    Prepare to build the package.
  build        Make this package ready for installation.
  copy         Copy the files into the install locations.
  haddock      Generate Haddock HTML documentation.
  clean        Clean up after a build.
  hscolour     Generate HsColour colourised code, in HTML format.
  register     Register this package with the compiler.
  test         Run the test suite, if any (configure with UserHooks).
  bench        Run the benchmark, if any (configure with UserHooks).
  upgrade      (command disabled, use install instead)
  help         Help about commands

For more information about a command use:
  cabal COMMAND --help

To install Cabal packages from hackage use:
  cabal install foo [--dry-run]

Occasionally you need to update the list of available packages:
  cabal update

You can edit the cabal configuration file to set defaults:
  /home/vagrant/.cabal/config
vagrant@vagrant-ubuntu-trusty-32:/usr/lib/haskell-packages$ cabal COMMAND --help
cabal: unrecognised command: COMMAND (try --help)
vagrant@vagrant-ubuntu-trusty-32:/usr/lib/haskell-packages$ cabal sandbox --help
cabal: unrecognised command: sandbox (try --help)

apt 安装的 Cabal 有点旧,这很可能是您 PATH 中的那个。它被安装到 /usr/bin。您可以查看:

which cabal

并查看版本:

cabal -v

您应该将 ~/.cabal/bin 中的那个放在您的 PATH 中第一个:

export PATH="$HOME/.cabal/bin:$PATH

(可能最好将其放入您的 ~/.bash_profile 或类似内容)

在我的系统上:

.whogan:~$ which cabal
/home/whogan/.cabal/bin/cabal

.whogan:~$ cabal -V
cabal-install version 1.22.6.0
using version 1.22.4.0 of the Cabal library 

.whogan:~$ /usr/bin/cabal -V
cabal-install version 1.16.0.2
using version 1.16.0 of the Cabal library 

编辑: 尝试使用新的 Vag运行t 盒子,运行 apt-get install haskell-platform 并从 git 安装:

[vagrant@vagrantbox:~] $ git clone git://github.com/haskell/cabal.git cabal-wip
Cloning into 'cabal-wip'...
remote: Counting objects: 48926, done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 48926 (delta 16), reused 0 (delta 0), pack-reused 48876
Receiving objects: 100% (48926/48926), 26.39 MiB | 10.37 MiB/s, done.
Resolving deltas: 100% (29033/29033), done.
Checking connectivity... done.

[vagrant@vagrantbox:~] $ cd cabal-wip
[vagrant@vagrantbox:~/cabal-wip][master] $ cabal install Cabal/ cabal-install/
Config file path source is default config file.
Config file /home/vagrant/.cabal/config not found.
Writing default configuration to /home/vagrant/.cabal/config
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.
Resolving dependencies...
Configuring Cabal-1.23.0.0...
Building Cabal-1.23.0.0...
Preprocessing library Cabal-1.23.0.0...
[ 1 of 85] Compiling Distribution.Lex ( Distribution/Lex.hs, dist/build/Distribution/Lex.o )
..
[85 of 85] Compiling Distribution.Simple ( Distribution/Simple.hs, dist/build/Distribution/Simple.o )
In-place registering Cabal-1.23.0.0...
Installing library in /home/vagrant/.cabal/lib/Cabal-1.23.0.0/ghc-7.6.3
Registering Cabal-1.23.0.0...
Installed Cabal-1.23.0.0
[1 of 1] Compiling Main             ( cabal-install/Setup.hs, cabal-install/dist/setup/Main.o )
Linking cabal-install/dist/setup/setup ...
Configuring cabal-install-1.23.0.0...
Building cabal-install-1.23.0.0...
Preprocessing executable 'cabal' for cabal-install-1.23.0.0...
[ 1 of 81] Compiling Distribution.Client.Utils.LabeledGraph ( Distribution/Client/Utils/LabeledGraph.hs, dist/build/cabal/cabal-tmp/Distribution/Client/Utils/LabeledGraph.o )
...
[81 of 81] Compiling Main             ( Main.hs, dist/build/cabal/cabal-tmp/Main.o )
Linking dist/build/cabal/cabal ...
Generating manual page dist/build/cabal/cabal.1 ...
Installing executable(s) in /home/vagrant/.cabal/bin
Installed cabal-install-1.23.0.0

已将 1.23.0.0 安装到 ~/.cabal/bin,但此后 PATH 仍指向系统一:

[vagrant@vagrantbox:~/cabal-wip][master] $ which cabal
/usr/bin/cabal
[vagrant@vagrantbox:~/cabal-wip][master] $ cabal -V
cabal-install version 1.16.0.2
using version 1.16.0 of the Cabal library

所以我修改把user/git版本放在第一位:

[vagrant@vagrantbox:~/cabal-wip][master] $ export PATH="~/.cabal/bin:$PATH"
[vagrant@vagrantbox:~/cabal-wip][master] $ which cabal
/home/vagrant/.cabal/bin/cabal
[vagrant@vagrantbox:~/cabal-wip][master] $ cabal -V
cabal-install version 1.23.0.0
compiled using version 1.23.0.0 of the Cabal library 

之后似乎还可以:

[vagrant@vagrantbox:~/cabal-wip][master] $ mkdir ~/tmp && cd ~/tmp
[vagrant@vagrantbox:~/tmp] $ cabal sandbox init
Writing a default package environment file to
/home/vagrant/tmp/cabal.sandbox.config
Creating a new sandbox at /home/vagrant/tmp/.cabal-sandbox

我使用的是 trusty64 而不是 trusty32,但我希望在这种情况下这并不重要。