How to completly remove packages installed by cabal?

12,579

You can delete the files yourself from the packages directory. However, the reason no command to do so is provided is there's in general no guarantee something may not have linked against them elsewhere, and so such deletions may cause breakages. That said, there's also a tool that goes and does the deletion for you if you really want it.

http://hackage.haskell.org/package/cabal-uninstall

And there's a tool with a bit more functionality that also lets you figure out what packages have no reverse deps, so at least no other packages break:

https://github.com/iquiw/cabal-delete

Share:
12,579
Alaya
Author by

Alaya

Major in Microelectronics. know some Haskell/c++/perl

Updated on June 19, 2022

Comments

  • Alaya
    Alaya about 2 years

    I am trying to learn cabal, and have tested several my own little projects, now I want to clean them up.

    Basically, if I am working without a sandbox, my workflow is:

    1. run cabal init
    2. edit src/Mylib.hs, and then edit mylibname.cabal file
    3. run cabal build
    4. run cabal repl and test my code
    5. run cabal install

    Now, I see my own project:

    1. installed into ~/.cabal/lib/x86-64-linux-ghc-7.10.1
    2. registered in ~/.ghc/package.conf.d

    I can write import Mylib in my other haskell source code, so I think the package is successfully installed.

    Then I want to uninstall the package, as the package itself is just meaningless experiment code.

    I read this article, who says that:

    There is no "cabal uninstall" command. You can only unregister packages with ghc-pkg:

     ghc-pkg unregister
    

    so I run

    ghc-pkg unregister mylibname 
    

    Now, it seems that the package is unregistered in ~/ghc/package.conf.d, however, there is still a compiled library in ~/.cabal/lib/x86-64-linux-ghc-7.10.1.

    So, how could I completly remove my project, could I just rm -rf the library in ~/.cabal?

  • Philippe Fanaro
    Philippe Fanaro about 3 years
    What a lazy implementation of a package manager. And that's lazy in a really bad sense. I know a lot of people who simply quit Haskell because the package management is so difficult to deal with. We need to abstract away these issues.
  • Shawn Eary
    Shawn Eary over 2 years
    @PhilippeFanaro - Probably why many people use Stack now, but I personally prefer Cabal when it doesn't bite me in the backside...
  • Enlico
    Enlico over 2 years
    in general no guarantee something may not have linked against them elsewhere isn't this, more in general, true for any software? Any software has dependencies on other software, and if we remove the latter we break the former. A package manager should keep track, I think, of these dependency relations, so it could tell the user "oh, no, if you remove this you break that".
  • sclv
    sclv about 2 years
    Except these are packages that users can link against independently of the package manager.