如何卸载 Cabal 软件包的版本?

“快乐栈精简版”让我很不爽,因为它现在的版本是“ Blaze-html”版本0.5,而它想要的是“0.4”版本。Cabal 说已经安装了 都有版本0.4.3.4和0.5.0.0。我想删除0.5.0.0,只使用旧版本。但是 cabal 没有“卸载”命令,当我尝试 ghc-pkg unregister --force blaze-html时,ghc-pkg说我的命令被忽略了。

我该怎么办?

更新 : 不要相信。虽然 ghc-pkg声明忽略该命令,但是 不是忽略了该命令。有了唐 · 斯图尔特公认的答案,你就可以删除你想删除的版本。

43645 次浏览

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

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

That should be sufficient.

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

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.

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.