📌 STICKY 📄 GUIDE ✓ SOLVED

[GUIDE] How to Set Up Cubical Agda + agda/cubical Library (2025 Edition)

Started by CubicalCat  •  Sat Jan 04, 2025 3:17 am Views: 8,842  •  Replies: 14  •  ✓ Marked as Solved
#1
🐱
CubicalCat ★ Path Meowster
Posts: 1,337
Joined: 2022-09-11
Rep: +888
♡ HoTT ∞-groupoid Agda dev
✔  This is a community-verified guide. Last updated January 2025. All steps tested on Linux, macOS, and NixOS.

Nyaa~! Welcome to the 2025 edition of the Cubical Agda setup guide, updated for the current Agda release! I keep seeing the same questions over and over so I finally wrote this up properly. Bookmark it. Pin it to your cat ear. nya~

⬡ Step 1 — Prerequisites

You need GHC + Cabal (or Stack) installed. The easiest way is via GHCup. Make sure you have:

  • GHC ≥ 9.4 recommended (9.8 tested for Agda 2.6.4+)
  • cabal-install ≥ 3.10, or stack ≥ 2.15
  • git (for cloning the cubical library)
  • Emacs or VS Code with agda-mode / cornelis
💡 Nix/NixOS users: skip to the NixOS guide — there's a much cleaner path for you via nixpkgs or a flake. This guide focuses on cabal.

⬡ Step 2 — Install Agda via Cabal

To download and compile Agda using cabal v2-build, you need a recent (2.4 or later) version of cabal-install. Then run:

$ cabal update
$ cabal install Agda

This puts the agda and agda-mode executables in ~/.cabal/bin. In order to be able to access these on your system you need to add them to your $PATH environment variable.

# Add to ~/.bashrc or ~/.zshrc:
export PATH="$HOME/.cabal/bin:$PATH"
source ~/.bashrc  # or restart terminal

Verify it works:

$ agda --version
Agda version 2.6.4.3
⚠️ Version pinning matters! The cubical library is version-sensitive. The library checks with a specific Agda version, and if you want to use a specific release of Agda, there is a compatibility table listing which releases of Agda are known to work with which release of the library.

⬡ Step 3 — Clone the agda/cubical Library

There is a standard agda/cubical library for Cubical Agda available at https://github.com/agda/cubical. Clone it somewhere stable — it won't "install" in the traditional sense; Agda reads it from wherever you put it.

$ mkdir -p ~/agda-libs
$ cd ~/agda-libs
$ git clone https://github.com/agda/cubical.git
$ cd cubical
# Optional: checkout a tagged release for stability:
$ git checkout v0.7  # check releases page for latest
💡 There's no compilation involved in installing an Agda library — you just have the source files and Agda will generate .agdai interface files on demand. No make required!

⬡ Step 4 — Register the Library with Agda

In order to make this library visible to Agda, add /path/to/cubical/cubical.agda-lib to ~/.agda/libraries and add cubical to ~/.agda/defaults (where path/to is the absolute path to where the agda/cubical library has been installed).

$ mkdir -p ~/.agda

# Register the library path:
$ echo "/home/youruser/agda-libs/cubical/cubical.agda-lib" >> ~/.agda/libraries

# Make it a default library (so you don't need .agda-lib per project):
$ echo "cubical" >> ~/.agda/defaults

Your ~/.agda/ directory should now look like:

~/.agda/
├── libraries      # one path per line to .agda-lib files
└── defaults       # library names to load by default

⬡ Step 5 — The --cubical Flag

To use the cubical mode, Agda needs to be run with the --cubical command-line option or with {-# OPTIONS --cubical #-} at the top of the file.

The recommended way to get access to the Cubical primitives is to add the following to the top of a file (this assumes that the agda/cubical library is installed and visible to Agda):

{-# OPTIONS --cubical #-}
open import Cubical.Core.Everything

Or if you just want the foundations prelude:

{-# OPTIONS --cubical #-}
open import Cubical.Foundations.Prelude

-- Now you can write things like:
myRefl :  {ℓ} {A : Set ℓ} {x : A} → x ≡ x
myRefl = refl

Other flag variants:

  • --cubical — full cubical mode, paths are native, univalence computes
  • --erased-cubical — a variant of Cubical Agda that is supported by the GHC backend
  • --cubical-compatible — specifies that the module is compatible with Cubical Agda; modules without this flag cannot be imported from --cubical modules

⬡ Step 6 — Test Your Setup

Create a file HelloCubical.agda:

{-# OPTIONS --cubical #-}
module HelloCubical where

open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat

-- A path is just a function I → A, nya~
three-is-three : 
three-is-three = 3

-- refl works definitionally
test : 1 + 2 ≡ 3
test = refl

Load it with C-c C-l in Emacs or via the command line:

$ agda HelloCubical.agda
Checking HelloCubical (/home/you/HelloCubical.agda).
Finished HelloCubical.
✅ If you see "Finished" with no errors — congrats, you have Cubical Agda! nya~

⬡ Common Errors & Fixes

Error: Library 'cubical' not found

Library 'cubical' not found.
  Add the path to its .agda-lib file to
  '~/.agda/libraries'

→ Double-check your ~/.agda/libraries file. The path must be absolute and point to the cubical.agda-lib file itself, not the directory.

Error: UnsupportedIndexedMatch warning spam

For day-to-day use of Cubical Agda, it is advisable to disable the UnsupportedIndexedMatch warnings. You can do this using the -WnoUnsupportedIndexedMatch option in an OPTIONS pragma or in your agda-lib file.

{-# OPTIONS --cubical -WnoUnsupportedIndexedMatch #-}

Error: imported module uses --without-K

Code that uses only --without-K can no longer be imported from code that uses --cubical. Thus it may make sense to replace --without-K with --cubical-compatible in library code, if possible.

Error: Agda version mismatch

Unsupported file format: ...

→ Your .agdai interface files were built with a different Agda version. Run agda --compile fresh or delete all _build/ and .agdai files and recheck.

— CubicalCat 🐱 | Questions below! nya~

↩ Quote ✏️ Edit 👤 Profile 📨 PM 📌 Sticky post
#2
🐾
PurrfectProofs ✦ Fiber Kitten
Posts: 203
Joined: 2023-11-02
Rep: +74
HIT enjoyer

Thank you so much for this!!! I've been struggling with the library version mismatch for weeks. nyaa~

One thing I'd add for anyone on macOS with Homebrew: installing Agda via brew install agda usually gives you an older version. The cabal method from this guide is definitely better if you need a specific version to match cubical.

Also the step about ~/.agda/defaults is a lifesaver — I didn't know you could set default libraries! I was adding {-# DEFAULT_LIBRARIES cubical #-} manually to every file lol

↩ Quote 👤 Profile 📨 PM
#3
😺
λ-Nekomata ⟐ Univalence Enjoyer
Posts: 512
Joined: 2023-04-17
Rep: +142
ua fanatic 1lab reader

Great guide! For completeness — the Cubical mode extends Agda with a variety of features from Cubical Type Theory. In particular, it adds computational univalence and higher inductive types, hence giving computational meaning to Homotopy Type Theory and Univalent Foundations.

So when people ask "why bother with cubical vs plain Agda + univalence axiom" — the answer is: in cubical, univalence computes. You can actually reduce transport along ua e to the underlying equivalence. No stuck terms!

💡 The key idea of Cubical Type Theory is to add an interval type I : IUniv. A variable i : I intuitively corresponds to a point in the real unit interval. This is what makes path types so natural.

Also worth mentioning: for a paper with details about Cubical Agda, see "Cubical Agda: a dependently typed programming language with univalence and higher inductive types" by Andrea Vezzosi, Anders Mörtberg, and Andreas Abel. Highly recommended reading!

↩ Quote 👤 Profile 📨 PM
#4
❄️
NixKitty ✦ Fiber Kitten
Posts: 389
Joined: 2023-07-22
Rep: +211
NixOS flake wizard

For the Nix users who clicked anyway — here's the quick version. In your flake.nix:

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  outputs = { nixpkgs, ... }:
    let pkgs = nixpkgs.legacyPackages.x86_64-linux;
    in {
      devShells.default = pkgs.mkShell {
        buildInputs = [
          pkgs.agda
          # agda/cubical is included as an Agda library in nixpkgs:
          (pkgs.agda.withPackages [pkgs.agdaPackages.cubical])
        ];
      };
    };
}

Then nix develop and you're done. The library path is automatically configured. No manual ~/.agda/libraries editing needed. This is the way. nya~

See the full NixOS guide at [GUIDE] Cubical Agda on NixOS with flakes for more detail.

↩ Quote 👤 Profile 📨 PM
#5
🙀
WinCatUser ◇ Newkitten
Posts: 12
Joined: 2025-01-01
Rep: +3

Hi! I'm on Windows 11. Will this work for me? The INSTALL.md on GitHub says something vague about Cygwin…

From agda/cubical INSTALL.md:
This file contains detailed instructions for how to install on Linux and Mac. Windows users might be able to use Cygwin to mimic these instructions, but this hasn't been tested.

That's not super encouraging lol 😅 Is WSL2 the way to go?

↩ Quote 👤 Profile 📨 PM
#6
🐱
CubicalCat ★ Path Meowster
Posts: 1,337
Joined: 2022-09-11
Rep: +888
♡ HoTT Agda dev
WinCatUser wrote:
Is WSL2 the way to go?

Yes, WSL2 is absolutely the recommended path on Windows! Once you're in WSL2 (Ubuntu or Debian), just follow the guide exactly as written above. It works perfectly. nya~

The native Windows experience for Agda is... rough. GHCup works on Windows but the Agda emacs mode has quirks with Windows paths. Cygwin is archaeologically interesting but not recommended in 2025.

Short version for Windows users:

  1. Install WSL2: wsl --install from PowerShell (admin)
  2. Open Ubuntu terminal, follow guide above from Step 1
  3. Use VS Code with the WSL extension + cornelis agda mode
  4. 🐱

There's a dedicated thread here: [GUIDE] Cubical Agda on Windows via WSL2

↩ Quote ✏️ Edit 👤 Profile 📨 PM
#7
🔮
HITsAndMisses ◈ Circle Kitten
Posts: 87
Joined: 2024-03-14
Rep: +29
S¹ enjoyer

Setup works great, thank you! One question — I'm trying to define a higher inductive type (the circle) and wanted to confirm the syntax is right:

{-# OPTIONS --cubical #-}
module MyCircle where
open import Cubical.Foundations.Prelude

data  : Set where
  base  : 
  loop  : base ≡ base

This seems to work but is it correct? Is this the canonical definition from the library?

↩ Quote 👤 Profile 📨 PM
#8
😺
λ-Nekomata ⟐ Univalence Enjoyer
Posts: 512
Joined: 2023-04-17
Rep: +142
ua fanatic

Yes, that definition is correct! Cubical Agda lets us directly define higher inductive types as datatypes with path constructors. Your circle is exactly right — base : S¹ is the point constructor and loop : base ≡ base is the path constructor.

The agda/cubical library defines S¹ exactly like this in Cubical.HITs.S1 (or Cubical.HITs.Circle depending on version). You can just import it:

open import Cubical.HITs.S1.Base
-- gives you: base, loop, and rec/elim principles

And functions out of HITs work by pattern matching on constructors — including path constructors:

-- Winding number example:
winding : 
winding base       = 0
winding (loop i)   = -- i : I, interpolating 0 ≡ 1

Check out the HIT Introduction thread for way more detail on defining and using HITs! nya~

↩ Quote 👤 Profile 📨 PM
#9
🌀
KanFillKitty ◈ Circle Kitten
Posts: 156
Joined: 2024-01-20
Rep: +44
kompilation

Can you say more about --erased-cubical? I want to compile my cubical proofs to a Haskell program and extract running code from them. Is that what it's for?

↩ Quote 👤 Profile 📨 PM
#10
🐱
CubicalCat ★ Path Meowster
Posts: 1,337
Joined: 2022-09-11
Rep: +888
♡ HoTT Agda dev
KanFillKitty wrote:
Can you say more about --erased-cubical? I want to compile to Haskell.

Great question! Agda added support for Erased Cubical Agda, a variant of Cubical Agda supported by the GHC backend, under the flag --erased-cubical.

The key idea: in full --cubical mode, paths and interval variables live at runtime, which means the GHC backend can't erase them cleanly. With --erased-cubical, all the cubical machinery (intervals, paths, transport, hcomp) is marked as erased — meaning it's verified at compile time but doesn't appear in the extracted Haskell.

This means you can:

  • Write cubical proofs for correctness guarantees
  • Compile the computational content to efficient Haskell
  • Use @0 (erased) annotations to control what gets erased
⚠️ The tradeoff: you can't pattern-match on paths at runtime in --erased-cubical. It's a more restricted mode. Think of it as "cubical types for proofs, regular Haskell types for computation."

See the dedicated thread: [Discussion] --erased-cubical and the GHC backend for examples! nya~

↩ Quote ✏️ Edit 👤 Profile 📨 PM
#11
🐈
TruncationNyan ◇ Newkitten
Posts: 5
Joined: 2025-01-05
Rep: +1

Hi nya! First post on CGPA! 🐱 Setup worked perfectly following this guide. I'm now trying to use propositional truncation. Is the import Cubical.HITs.PropositionalTruncation? Getting a "not found" error.

↩ Quote 👤 Profile 📨 PM
#12
🐾
PurrfectProofs ✦ Fiber Kitten
Posts: 207
Joined: 2023-11-02
Rep: +75
TruncationNyan wrote:
Is the import Cubical.HITs.PropositionalTruncation?

Welcome to CGPA!! 🎉 The correct module path is:

open import Cubical.HITs.PropositionalTruncation
-- gives you: ∥_∥, ∣_∣, squash, rec, etc.

If you're getting "not found," it's almost always one of three things:

  1. The --cubical option is missing from your OPTIONS pragma
  2. The cubical library isn't registered in ~/.agda/libraries (re-check Step 4!)
  3. Version mismatch — the module might have been reorganised between library versions

If all else fails, just open the cloned library folder and search: find ~/agda-libs/cubical -name "*.agda" | xargs grep -l "PropositionalTruncation" and you'll find it! nya~

↩ Quote 👤 Profile 📨 PM
#13
🐱
CubicalCat ★ Path Meowster
Posts: 1,337
Joined: 2022-09-11
Rep: +888
♡ HoTT Agda dev
✔  Guide marked as SOLVED/complete. All common questions have been answered! Please open a new thread for specific issues.

Marking this as solved now that the main questions are covered. Nyaa~ 🐱 I'll continue updating the OP as Agda versions change.

Quick summary of resources for further reading:

— CubicalCat 🐱 | Thanks everyone for contributing! nya~

↩ Quote ✏️ Edit 👤 Profile 📨 PM
💬 Quick Reply — Re: [GUIDE] How to Set Up Cubical Agda + agda/cubical Library (2025 Edition)
👁 Users viewing this thread: CubicalCat, λ-Nekomata, WinCatUser, 4 guests  |  Total: 7 viewers