Install the toolchain with GHCup
| Linux and macOS | |
| Windows | |
| Pin a compiler version | |
| Check the install |
Linux and macOS
GHCup is one shell script that downloads a compiler, a package manager, and a version switcher. It writes everything into ~/.ghcup and never touches system packages.
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
The installer asks three questions. Answer P to prepend the GHCup environment to your shell profile, N to skip the language server for now, and N to skip the Stack install. Then reload the shell:
source ~/.ghcup/env
On a fresh machine the script may need a C compiler (gcc) and the ncurses headers. On Debian and Ubuntu the packages are build-essential, libgmp-dev and libncurses-dev; on Fedora they are gcc, gmp-devel and ncurses-devel.
Windows
Run the same installer from PowerShell. It needs no administrator rights and no Visual Studio:
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-WebRequest https://get-ghcup.haskell.org -UseBasicParsing | Invoke-Expression
Windows builds of GHC ship as MSYS2 packages, and GHCup installs a private MSYS2 under %APPDATA%. Keep the default answer when the installer offers to do that.
Pin a compiler version
GHCup installs the recommended compiler, but a project can need an older one. Install and select any version explicitly:
ghcup install ghc 9.10.1
ghcup set ghc 9.10.1
ghcup list
The last command prints a table with one row per version and a marker on the active one. Switching back is the same ghcup set call with another number, so two projects with different compilers never fight.
Check the install
Three version checks tell you whether the path is wired correctly. All of them must answer without a command not found message:
ghc --version
ghci --version
cabal --version
cabal-install version 3.12.1.0 compiled using version 3.12.1.0 of the Cabal library
If ghc works but a new terminal forgets it,
the shell profile line is missing. Add
source ~/.ghcup/env to
~/.bashrc or ~/.zshrc
and open a new window.
Next:
GHCi: the interactive shell
Article author: Arthur Isaev