My cabal packages are FUBAR; how can I purge them and start over?

14,647

Solution 1

Cabal doesn't keep track of what it's installed, it just uses ghc's library mechanism (or that of some other compiler if you're not using ghc), so you can use rm -r ~/.ghc to remove all locally-installed libraries.

If you have multiple ghc's installed, and you only want to remove the libs for a specific ghc, delete the subdirectory corresponding to whichever ghc you want to remove.
For example, I could remove everything I've installed for ghc-7.6.0 with rm -r ~/.ghc/x86_64-linux-7.6.0.20120810
You can also use this to preserve your ghci_history if you like.

ll ~/.ghc/
total 24
-rw-r--r-- 1 johnl johnl 2300 Aug 21 11:47 ghci_history
drwxr-xr-x 3 johnl johnl 4096 Jun 17 19:09 x86_64-linux-6.12.3
drwxr-xr-x 3 johnl johnl 4096 May 17 08:17 x86_64-linux-7.2.1
drwxr-xr-x 3 johnl johnl 4096 May 16 17:34 x86_64-linux-7.4.1
drwxr-xr-x 3 johnl johnl 4096 Jun 15 08:21 x86_64-linux-7.4.2
drwxrwxr-x 3 johnl johnl 4096 Aug 15 12:37 x86_64-linux-7.6.0.20120810

Edit: ~/.cabal/world is a list of installed packages with version constraints as specified by the user. So in most cases, it would include e.g. mtl -any. If you've installed packages with specific versions, such as by issuing cabal install mtl-2.1.1, it will record that version. You should be able to either delete the world file and start over, or if you look it over and the dependencies are acceptable, you could try just running cabal install world. Or you could ignore it and not use cabal's world support (that's what I do).

Solution 2

This ghc-pkg-reset shell script cleans both ~/.ghc/ and ~/.cabal/, a little more selectively. (And the accompanying ghc-pkg-clean script can help recover from a confused package installation, perhaps avoiding a reset.) I find these useful.

Share:
14,647
jberryman
Author by

jberryman

Brandon Simmons is a flutist, photographer and hacker living in Richmond, VA. Some of my open source code is on github and on hackage, and you can check out my SO careers profile for details.

Updated on June 12, 2022

Comments

  • jberryman
    jberryman about 2 years

    I forgot to enable building libs for profiling in my ~/.cabal/config before installing a bunch of packages on a new machine and now a --reinstall world to try to fix the situation has left everything broken (naturally).

    I think it's a better use of my time to just purge everything. How do I do that correctly?

  • jberryman
    jberryman almost 12 years
    Great. Thanks! But how does ~/.cabal/world play in here?
  • chwarr
    chwarr over 8 years
    For those on Windows, the per-user state is stored, by default, under %APPDATA%\ghc and %APPDATA%\cabal.