2012-05-14 60 views
77

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表示我的命令已被忽略。如何卸載Cabal軟件包的一個版本?

我該怎麼辦?

UPDATE不要相信它。雖然ghc-pkg聲稱忽略該命令,但命令不是而被忽略。隨着唐斯圖爾特公認的答案,你可以刪除你想要消除的版本。

+2

'ghc-pkg list blaze-html'?你確定你是正確的用戶嗎?也許明確說明版本是未註冊的? – ivanm

+1

@ivanm謝謝你的提問。結果'ghc-pkg' *騙給我! –

+0

http://stackoverflow.com/questions/7252193/can-cabal-not-un-install-packages的副本的排序,但我不願意舉旗,因爲這個更好:) –

回答

89

您可以ghc-pkg unregister特定的版本,像這樣:

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

這應該是足夠了。

+17

一旦未註冊,是否有任何文件應該被修剪? –

+0

其他地方的評論提到,ghc-pkg留下文件夾? – CMCDragonkai

+0

在你的'〜/ .cabal /'文件夾中查看有關pkgs和二進制文件的位置的信息 – Leahcim

6

下面是我用來卸載軟件包的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 
+1

我剛剛在Mac上試過這個,它似乎不起作用。 – pyrrhic

20

也有cabal-uninstall包,它提供了一個cabal-uninstall命令。它取消註冊包並刪除該文件夾。值得一提的是,它通過--forceghc-pkg unregister,所以它可以打破其他包。

+1

'cabal uninstall'導致'cabal:unrecognized command:uninstall(try --help)' –

+2

@StevenShaw - 我提供的鏈接轉到您需要安裝才能使用的hackage包。我會推薦唐的回答,那就是我使用的。 – Davorak

+0

從上面的@Tobu註釋中,[cabal-delete](https://github.com/iquiw/cabal-delete)怎麼樣?比cabal卸載更好還是更強大? –

23

如果你是一個沙箱外:

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

如果你是一個cabal sandbox內:

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

第一--hc-pkg參數分隔符。這以沙盒感知的方式運行ghc-pkg