How can I uninstall a version of a Cabal package?

后端 未结 4 1139
春和景丽
春和景丽 2020-12-12 11:47

Happstack Lite is breaking on me because it\'s getting blaze-html version 0.5 and it wants version 0.4. Cabal says that both versions 0.4.3.4 and 0.5.0.0 are insta

相关标签:
4条回答
  • 2020-12-12 12:27

    There is also the cabal-uninstall package which provides a cabal-uninstall command. It unregisters the package and deletes the folder. It is worth mentioning though that it passes --force to ghc-pkg unregister so it can break other packages.

    0 讨论(0)
  • 2020-12-12 12:31

    Here's a shell script I use to uninstall a package. It supports multiple installed versions of GHC and also wipes relevant files (but is provided without warranty, don't blame me if you hose your installation!)

    #!/bin/bash -eu
    # Usage: ./uninstall.sh [--force | --no-unregister] pkgname-version
    
    # if you set VER in the environment to e.g. "-7.0.1" you can use
    # the ghc-pkg associated with a different GHC version
    : ${VER:=}
    
    if [ "$#" -lt 1 ]
    then
            echo "Usage: $0 [--force | --no-unregister] pkgname-version"
            exit 1
    fi
    
    if [ "$1" == "--force" ]
    then force=--force; shift; # passed to ghc-pkg unregister
    else force=
    fi
    
    if [ "$1" == "--no-unregister" ]
    then shift # skip unregistering and just delete files
    else
            if [ "$(ghc-pkg$VER latest $1)" != "$1" ]
            then
                    # full version not specified: list options and exit
                    ghc-pkg$VER list $1; exit 1
            fi
            ghc-pkg$VER unregister $force $1
    fi
    
    # wipe library files
    rm -rfv -- ~/.cabal/lib/$1/ghc-$(ghc$VER --numeric-version)/
    
    # if the directory is left empty, i.e. not on any other GHC version
    if rmdir -- ~/.cabal/lib/$1 
    then rm -rfv -- ~/.cabal/share/{,doc/}$1 # then wipe the shared files as well
    fi
    
    0 讨论(0)
  • 2020-12-12 12:37

    If you are outside a sandbox:

    ghc-pkg unregister --force regex-compat-0.95.1
    

    If you are inside a cabal sandbox:

    cabal sandbox hc-pkg -- unregister attoparsec --force
    

    The first -- is the argument separator for hc-pkg. This runs ghc-pkg in a sandbox aware manner.

    0 讨论(0)
  • 2020-12-12 12:45

    You can ghc-pkg unregister a specific version, like so:

    $ ghc-pkg unregister --force regex-compat-0.95.1
    

    That should be sufficient.

    0 讨论(0)
提交回复
热议问题