11

I'm a newbie to haskell and cabal, so I'm probably missing something simple.

I updated cabal-install:

sudo cabal install cabal-install
Password:
Resolving dependencies...
Configuring cabal-install-1.22.0.0...
Building cabal-install-1.22.0.0...
Installed cabal-install-1.22.0.0
Updating documentation index

However cabal --version says:

cabal-install version 1.18.0.5
using version 1.18.1.4 of the Cabal library 

What happened to cabal-install 1.22.0.0?

daj
  • 6,962
  • 9
  • 45
  • 79

3 Answers3

13

There are two ways of making cabal install packages globally. Note that, as a result, cabal may require sudo.

This command will install <PACKAGE> globally:

$ cabal install <PACKAGE> --global

As a more general solution, edit the file ~/.cabal/config and set user-install to False. This will automatically set the --global flag so you can just write cabal install <PACKAGE> without any worry. Here's a snippet of my config file:

...
-- split-objs: False
-- executable-stripping: True
user-install: False
-- package-db:
-- flags:
...

You may also want to set root-cmd to sudo if it's not already, so that cabal will automatically prompt for the root password when it encounters a permission problem.

There's some more info online here.

AJF
  • 11,767
  • 2
  • 37
  • 64
5

I see that there's an updated cabal at ~/Library/Haskell/bin, so I could replace /usr/bin/cabal with a symbolic link to this copy or I could copy this binary to /usr/bin.

I'm still interested if there is a more elegant/canonical way to make sure the new cabal is what gets used by default.

daj
  • 6,962
  • 9
  • 45
  • 79
2

TLDR: Try running hash -r

Bash has a PATH hashtable that maps commands to the location of binaries. You may still have an old version of cabal installed somewhere in your PATH (possibly in a sandbox). Since cabal is not a new command, the hashtable will keep serving up the old version. hash -r rebuilds the hashtable, so the shell will correctly find the new version (providing it appears earlier in your path than the old one).

eigensheep
  • 160
  • 5
  • Small nit: `hash -r` *clears* the hash table. It is then rebuilt on a per-command basis each subsequent time an unqualified path is invoked as a command. – BMDan Jun 09 '19 at 17:14