LinuxCommandLibrary

cabal

Build and manage Haskell projects

TLDR

Search and list packages from Hackage

$ cabal list [search_string]
copy

Show information about a package
$ cabal info [package]
copy

Download and install a package
$ cabal install [package]
copy

Create a new Haskell project in the current directory
$ cabal init
copy

Build the project in the current directory
$ cabal build
copy

Run tests of the project in the current directory
$ cabal test
copy

SYNOPSIS

cabal [global-options] <command> [<args>]

PARAMETERS

--help, -h, -?
    Show help summary

--verbose=n, -v n
    Set verbosity level (0-3)

--version
    Show cabal version

--numeric-version
    Show numeric cabal version

--builddir=DIR
    Custom build directory

--project-file=FILE
    Specify cabal.project file

--dry-run
    Don't execute, just show plan

--ignore-project
    Ignore cabal.project

--enable-profiling
    Build with profiling

--write-ghc-environment-files=always|never|auto
    Control GHC environment files

--lib
    Build only libraries

--exe
    Build only executables

DESCRIPTION

Cabal is the standard build system and package manager for Haskell projects on Linux and other platforms. It manages dependencies, builds executables and libraries, runs tests, and installs packages from the Hackage repository.

Projects are described in a .cabal file specifying metadata, libraries, executables, test suites, and dependencies. A companion Setup.hs file (generated by default) implements the build backend.

Key workflows include: cabal init to create projects, cabal update for package lists, cabal build to compile, cabal install for global/local installs, and cabal test for testing. Newer versions (3.x) introduce project-based builds with cabal.project files for multi-package workspaces, solver improvements, and native dependency solving.

Cabal integrates with GHC and supports flags for optimization, profiling, and cross-compilation. It's widely used but sometimes paired with Stack for reproducible builds. As of 2023, Cabal 3.10+ emphasizes reproducibility and performance.

CAVEATS

Cabal v1 workflows deprecated; use v2-build or later. Sandboxes removed in 3.0+. Requires GHC installed. Solver may need flags for complex deps.

COMMON SUBCOMMANDS

init: Create new project.
build: Compile project.
install: Install package.
update: Update package list.
test: Run tests.
run: Execute main.
repl: Launch GHCi.

INSTALLATION

Install via ghcup install cabal or Haskell Platform. Requires GHC.

HISTORY

Developed 2003-2005 by Duncan Coutts for GHC 6.4. Evolved through versions: v1 (simple builds), v2 (project files, 2018), v3 (new solver, 2020+). Maintained by Haskell.org committee.

SEE ALSO

ghc(1), ghci(1), runhaskell(1)

Copied to clipboard