2

I have done the below steps to install cabal . I have already installed haskell platform using sudo apt-get install haskell-platform

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/

However when I try to initialize a sandbox, it throws error as below.

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

Adding more details:

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)
Zack
  • 2,078
  • 10
  • 33
  • 58
  • 1
    `cabal sandbox` is only available with cabal-install 1.18 and above. What does `cabal --version` tell you? – duplode Nov 11 '15 at 02:53
  • 1
    I believe Ubuntu's package system has an outdated haskell-platform (outdated by at least a couple years it looks like, which is very outdated). I would suggest installing it from a different source. – David Young Nov 11 '15 at 03:03
  • 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 – Zack Nov 11 '15 at 03:07
  • @DavidYoung : I added more details. Check – Zack Nov 11 '15 at 03:10
  • @duplode: Added more details – Zack Nov 11 '15 at 03:10
  • 2
    @Zack Well, like I said, I'd suggest getting haskell-platform/ghc from a more up-to-date source. That installation probably has, at best, GHC 7.6.3 which is two (soon to be three) major releases behind the latest stable release (and there is a large difference in the number of features. You will likely run into quite a few incompatibilities with Haskell libraries). You can probably fix this specific problem, though, by just upgrading cabal (this won't upgrade the GHC compiler though). This can be done with `cabal update && cabal install cabal-install`. – David Young Nov 11 '15 at 04:04
  • I don't specifically know what you are doing, but an alternative these days is to just use [stack](https://github.com/commercialhaskell/stack). – Sibi Nov 11 '15 at 05:35

1 Answers1

4

The Cabal installed by apt is a little older and this is likely the one in your PATH. It gets installed to /usr/bin. You can check with:

which cabal

And to see the version:

cabal -v

You should put the one in ~/.cabal/bin in your PATH first with:

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

(Probably best to put this in your ~/.bash_profile or similar)

On my system:

.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 

Edit: Tried with a new Vagrant box, ran apt-get install haskell-platform and install from 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

It's installed 1.23.0.0 to ~/.cabal/bin, but after this the PATH is still pointing to the system one:

[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

So I modify to put the user/git version first:

[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 

It seems OK after that:

[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

I used trusty64 rather than trusty32 but I would hope that's not significant in this case.

Will Hogan
  • 909
  • 4
  • 9
  • Your answer is not helping me in any form. Could you please elaborate how to fix the error? Cabal is already in my path as mentioned in my post. – Zack Nov 11 '15 at 03:11
  • I know it's in your `PATH`, my point is that the system-level install is first in your `PATH` and this one differs from the user-level install in `~/.cabal/bin`. To fix this, as I said, you modify your path to put the user-level one first using `export PATH="$HOME/.cabal/bin:$PATH"`. This is also referenced in the blog post where they state "That’s all! Now you have the latest version of the cabal tool installed under ~/.cabal/bin". What is the output of `which cabal`? If it isn't `~/.cabal/bin` then you need to fix your path. – Will Hogan Nov 11 '15 at 04:43
  • Okay. Will try this. May be I missed this step. Thanks. – Zack Nov 11 '15 at 04:54
  • I see you've noted the path in the other thread above and you've somehow got 1.16 in `~/.cabal/bin`. Though I don't understand how that can happen with an install from git sources, you should probably go with David Young's suggestion. – Will Hogan Nov 11 '15 at 04:55
  • Thanks. I was able to do it interactively by logging into VM. However I am facing problems when doing the same through vagrantfile. Can you check this post: http://stackoverflow.com/questions/33645957/cabal-getting-installed-in-root-directory-instead-of-home-vagrant-directory-usi – Zack Nov 11 '15 at 07:30