【问题标题】:How can I uninstall a version of a Cabal package?如何卸载 Cabal 软件包的某个版本?
【发布时间】:2012-05-21 13:20:35
【问题描述】:

Happstack Lite 让我失望了,因为它正在获取 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 声称忽略该命令,但该命令并没有 被忽略。并且使用唐斯图尔特接受的答案,您可以准确删除您希望删除的版本。

【问题讨论】:

  • ghc-pkg list blaze-html ?您确定您以正确的用户身份运行它吗?也许明确说明要取消注册的版本?
  • @ivanm 感谢您的提问。原来ghc-pkg骗了我!
  • 类似于stackoverflow.com/questions/7252193/…,但我不愿意标记它,因为这个更好:)
  • cabal-delete 非常适合查找和删除孤立的包。
  • @Tobu cabal-uninstall mentioned in answer below 怎么样? cabal-delete 更强大吗?它可以与 cabal 沙箱一起使用(cabal exec -- cabal-delete 是否可以正常工作并从沙箱中删除包)?为什么不把这个也作为答案呢?它看起来是个不错的工具。

标签: haskell ghc cabal


【解决方案1】:

你可以ghc-pkg unregister一个特定的版本,像这样:

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

应该够了。

【讨论】:

  • 一旦未注册,是否有任何文件应该被修剪?
  • 其他地方的评论提到 ghc-pkg 会留下文件夹?
  • 查看您的 ~/.cabal/ 文件夹,了解有关 pkg 和二进制文件所在位置的信息
【解决方案2】:

这是我用来卸载软件包的 shell 脚本。它支持多个已安装的 GHC 版本,还可以擦除相关文件(但不提供保修,如果您安装了软管,请不要怪我!)

#!/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

【讨论】:

  • 我刚在 Mac 上试了一下,好像不行。
【解决方案3】:

还有一个cabal-uninstall 包,它提供了一个cabal-uninstall 命令。它取消注册包并删除文件夹。值得一提的是,它将--force 传递给ghc-pkg unregister,因此它可以破坏其他包。

【讨论】:

  • cabal uninstall 导致cabal: unrecognised command: uninstall (try --help)
  • @StevenShaw - 我提供的链接指向您需要安装才能使用的 hackage 包。我会推荐唐的答案,这就是我使用的。
  • @Tobu 以上评论中的cabal-delete 怎么样?它比 cabal-uninstall 更好或更强大吗?
【解决方案4】:

如果您在沙盒之外:

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

如果您在cabal sandbox 内:

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

第一个--hc-pkg 的参数分隔符。这会以沙盒感知方式运行 ghc-pkg

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 2012-05-19
    • 2021-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    相关资源
    最近更新 更多