Cabal is a system for building and packaging Haskell libraries and programs. It defines a common interface for package authors and distributors to easily build their applications in a portable way. Cabal is part of a larger infrastructure for distributing, organizing, and cataloging Haskell libraries and programs.
The term cabal can refer to either: cabal-the-spec (.cabal files), cabal-the-library (code that understands .cabal files), or cabal-the-tool (the cabal-install package which provides the cabal executable); usually folks are referring to cabal-the-tool when they say cabal.
To install the cabal executable you can use ghcup (if you're using Linux), the Haskell Platform, install the cabal-install package from your distributions package manager (if using Linux or Mac), or download the source or prebuilt binary from the Download page.
If you already have the cabal executable you can upgrade it by running:
cabal install Cabal cabal-install
If the above command failed for any reason see the Update Troubleshooting section below.
Sometimes the older installed version is still on the program search
$PATH, you can check you're running the
latest version with the command below. If it doesn't match the output of
the cabal-install command above you'll
need to update it.
Start by installing the cabal executable (see the previous section) and the Haskell compiler ghc (see the GHC download docs).
mkdir myproject && cd myproject
Before you try anything else, if you already have a new-ish version of cabal
you can use the v2/new commands. Try the following:
cabal new-install Cabal cabal-install
If this works update the cabal command on your path with the version installed.
ERROR: cabal: The following packages are likely to be broken by the reinstalls: ...
Use --force-reinstalls if you want to install anyway.
This can happen if your package archive gets into a broken state. How to fix this depends on the situation. Sometimes re-running the command with --force-reinstalls works, other times you have to remove your whole package archive and start over again.
Thankfully this doesn't happen very often, if you run into this issue ask a question on StackOverflow.