What's the best workaround for not having "cabal upgrade"?
Solution 1
This bit of shell hackery works for me on OS X:
cabal list --simple-output --installed | awk '{print $1}' | uniq | xargs -I {} cabal install {} --reinstall
EDIT: Now forces a reinstall, and avoids installing a package more than once when more than one version is present. Thanks for the comments!
EDIT YEARS LATER: Now that Cabal sandboxes and Stack exist, I strongly recommend against trying to upgrade packages in place. You'll end up with far fewer headaches if you instead can just wipe out an existing sandbox and reinstall up-to-date dependencies.
Solution 2
The .cabal/world
file contains a list of every package you installed explicitly (listed in a cabal install
command, as opposed to pulled through dependencies). Trim it to remove packages that are only useful as dependencies, packages that are deprecated, and version-locked packages that you'd rather upgrade.
Cabal doesn't know how to clean-up after itself, but you can remove almost everything. The next command will reinstall from .cabal/packages
(a tarball cache):
cp -t bin .cabal/bin/cabal
rm -rf .cabal/{bin,lib,share} .ghc/*-*-*/
ghc-pkg check |&egrep -- '^[A-Za-z0-9-]+-[0-9]' |xargs -n1 --no-run-if-empty ghc-pkg unregister
Now reinstall everything that was manually installed:
cabal install world --upgrade-dependencies --force-reinstalls
Comments
-
gatoatigrado almost 2 years
I want to upgrade all packages, not just a specific one with
cabal install --upgrade-dependencies
. -
Thomas M. DuBuisson almost 13 yearsDon't forget the
--reinstall
flag on that lastcabal install
command. -
hvr almost 13 yearsShouldn't there be a
uniq
filter after theawk
step? At least in my environment it would callcabal install
multiple times with the same argument... also, it might not be desirable to upgrade the system libraries bundled with GHC, such asbase
-
Chris.Q almost 10 years@ThomasM.DuBuisson, @acfoltzer. Should the
--reinstall
in the command change to--force-reinstall
? I currently have cabal with version 1.16.0.2. When I upgrade all packages, it constantly reminds that "The following packages are likely to be broken by the reinstalls...<the list of packages>... Use --force-reinstalls if you want to install anyway." -
Leon Mergen almost 10 yearsAs far as I understand,
cabal install
lies. The better approach would be to useghc-pkg list --user
, so you never touch GHC global packages. -
orome almost 9 yearsIs this still a valid approach? Is there a better alternative? It seems odd (stupid actually) that Cabal provides no way to keep package uptodate!
-
acfoltzer almost 9 years@raxacoricofallapatorius at this point, I would recommend using Cabal sandboxes or Stack, which are easy to wipe and start over, rather than reinstalling new versions in existing package databases