100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Installing GHC and Stack

How to set up a working Haskell toolchain -- GHC, Cabal, Stack, and HLS -- using GHCup, and the daily commands you'll use to build and run projects.

FoundationsBeginner7 min readJul 10, 2026
Analogies

Installing the Toolchain with GHCup

The modern, recommended way to install a Haskell toolchain is GHCup, a cross-platform installer script that manages GHC (the compiler), Cabal (the base package manager and build tool), Stack (a higher-level project and dependency manager), and HLS (the Haskell Language Server for editor tooling) as independently switchable versions. Running curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh on Linux or macOS downloads GHCup and walks you through installing a default GHC version, after which ghc --version and ghci --version should both report the installed release.

🏏

Cricket analogy: GHCup managing multiple GHC versions side by side is like an international squad maintaining separate red-ball and white-ball setups -- you switch tools (ghcup set ghc 9.6.4) the way a captain switches formats without discarding either setup.

bash
# Install GHCup (Linux / macOS)
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

# Verify the toolchain
ghc --version
ghci --version
cabal --version
stack --version

# List and switch installed GHC versions
ghcup list
ghcup set ghc 9.6.4

On Windows, GHCup ships a PowerShell installer instead of the curl-based shell script; run it from an elevated PowerShell prompt and it will configure MSYS2 automatically for native library dependencies.

Stack and Reproducible Builds

Stack is a build tool built on top of Cabal and GHCup that adds reproducible builds through curated package snapshots called resolvers -- for example lts-22.13 pins an exact, mutually-compatible set of package versions from Stackage so that stack build produces the same result on every machine, unlike plain Cabal, which resolves dependencies against the ever-changing Hackage index unless a cabal.project.freeze file is used. stack new my-project scaffolds a new project directory with a .cabal file, a stack.yaml resolver file, and a src/Main.hs entry point ready to build with stack build and run with stack run.

🏏

Cricket analogy: Stack's resolver pinning every package to a known-compatible version is like an ICC tournament using a fixed, pre-approved kit list so every team's equipment is guaranteed compatible with the match regulations, unlike a friendly match with no such guarantee.

bash
# Scaffold a new Stack project
stack new my-project
cd my-project

# Build and run it
stack build
stack run

The Daily Workflow: ghci, stack build, stack ghci

After installation, three commands form the daily workflow: ghci launches an interactive REPL for quickly evaluating expressions and loading modules with :load Main.hs or :l Main.hs; stack build compiles a project according to its stack.yaml and .cabal files; and stack ghci opens a REPL with the project's own dependencies already in scope, which is what you want when experimenting with functions from a library your project depends on rather than plain GHCi's bare environment.

🏏

Cricket analogy: Using ghci for a quick one-off expression versus stack ghci for full project context is like a batter taking a few throwdowns in the nets versus playing an actual practice match with the full XI and match conditions loaded.

Don't mix a globally-installed cabal install package set with a Stack project's resolver-pinned dependencies -- loading mismatched versions of the same library in the same session is a common source of confusing 'no instance for' or symbol-clash errors for beginners.

  • GHCup is the recommended cross-platform installer for GHC, Cabal, Stack, and HLS.
  • ghc --version and ghci --version confirm a working compiler and REPL after install.
  • Stack adds reproducible builds via curated Stackage resolvers such as lts-22.13.
  • stack new my-project scaffolds a .cabal file, stack.yaml, and src/Main.hs.
  • stack build compiles a project; stack run builds and executes it.
  • stack ghci opens a REPL with the project's own dependencies already in scope.
  • Avoid mixing global Cabal-installed packages with Stack's pinned resolver dependencies.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#HaskellStudyNotes#InstallingGHCAndStack#Installing#GHC#Stack#Toolchain#DataStructures#StudyNotes#SkillVeris