Skip to content

Install

You need opam, OCaml’s package manager, and OCaml 5.5 or later. Spindle brings dune, the build tool, with it.

1. Install opam

brew install opam
bash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)"
winget install Git.Git OCaml.opam

Spindle should work on Windows, but it is not tested there. If something fails, WSL gives you a Linux to follow the Linux steps in.

2. Set up OCaml

opam init

Answer yes when it offers to set up your shell. This installs the latest OCaml, which takes a few minutes. Then let this terminal see it – a new terminal does by itself:

eval $(opam env)
(& opam env) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ }
Already had opam?

Check ocaml -version. If it is older than 5.5, make a switch – an environment of its own – with the latest OCaml:

opam switch create spindle ocaml-base-compiler
eval $(opam env)

3. Install Spindle

opam repo add hypha https://github.com/hyphatech/opam-repository.git
opam install spindle

This installs the framework and everything it needs, dune and the ppx_wiretype deriver included. The database and the command line are packages of their own, so an app that uses neither never installs them; their tutorials install them when you get there:

Package Libraries What for
spindle spindle, spindle.http, spindle.client The framework, HTTP itself, and a client for calling other servers
spindle-postgres spindle-postgres Database
spindle-cli spindle-cli Client schemas

Check it worked

ocaml -version
The OCaml toplevel, version 5.5.1
dune --version
3.24.2
opam list spindle

It lists spindle with a version, not --, under Installed.

OCaml 5.5 or later, dune 3.19 or later and an installed spindle mean you are ready.

Your editor

For completion, types on hover and errors as you type, install the language server, then the OCaml Platform extension in VS Code – or the OCaml support of your editor:

opam install ocaml-lsp-server

A program names the libraries it uses in its dune file; your first app writes one, next.