beginner tooling

Hello OCaml: Your First Project with Dune

Set up an OCaml project from scratch with dune, write a small CLI tool, and run it.

This tutorial walks you through creating your first OCaml project using dune.

Install opam and OCaml

You need opam (the OCaml package manager) and a recent OCaml compiler.

bash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)"
opam init
opam switch create 5.3.0

Create a project

mkdir hello && cd hello
dune init project hello

Dune generates a basic project layout. Open bin/main.ml and replace its contents:

let () = print_endline "Hello from OCaml"

Build and run:

dune exec bin/main.exe

You should see Hello from OCaml printed to your terminal.