CSE307 · Programming Languages · 2026 Spring

OCaml Development Environment Setup

A step-by-step guide to set up an OCaml development environment using Docker and VS Code Dev Containers.

Prerequisites

Make sure you have the following before you begin.

📅
Operating System
macOS 12+  |  Windows 10+
🐳
Docker Desktop
Will be installed in this guide
🛠
Visual Studio Code
💾
Disk Space
~4 GB free for Docker image
🐳 Step 1: Install Docker Desktop

Select your operating system to see the matching instructions.

🌱 macOS
📱 Windows
🌱

macOS — Install Docker Desktop

1

Download Docker Desktop
Visit docker.com/products/docker-desktop and download the installer for macOS.

Choose Apple Silicon if you have an M1/M2/M3/M4 Mac, or Intel for older Macs. Check via > About This Mac.
2

Install and launch Docker Desktop
Open the downloaded .dmg file, drag Docker to Applications, and launch it. Allow any system permissions when prompted.

3

Verify Docker is running
Open Terminal and run:

bash
docker --version

You should see a version number like Docker version 27.x.x.

📱

Windows — Install Docker Desktop

1

Enable WSL 2 (if not already enabled)
Open PowerShell as Administrator and run:

powershell
wsl --install

Restart your computer if prompted.

WSL 2 (Windows Subsystem for Linux) is required by Docker Desktop on Windows. If you already have WSL 2, skip this step.
2

Download Docker Desktop
Visit docker.com/products/docker-desktop and download the installer for Windows.

3

Install and launch Docker Desktop
Run the installer, ensure "Use WSL 2 instead of Hyper-V" is checked, and follow the prompts. Launch Docker Desktop after installation.

4

Verify Docker is running
Open PowerShell and run:

powershell
docker --version

You should see a version number like Docker version 27.x.x.

🛠 Step 2: Install VS Code Dev Containers Extension

This extension lets VS Code develop directly inside a Docker container.

🔌

Install the Extension

1

Open Visual Studio Code.

2

Open the Extensions view
Press Ctrl+Shift+X on Windows/Linux, or Cmd+Shift+X on macOS.

3

Search for Dev Containers (by Microsoft) and click Install.

🚀 Step 3: Clone the Repository & Open in Dev Container

The assignment repository includes a pre-configured Dev Container. Just clone and open.

📦

Clone the Assignment Repository

1

Clone the repository
Open a terminal and run:

bash
git clone https://github.com/dgistpl/CSE307-2026spring.git
2

Open the folder in VS Code

bash
code CSE307-2026spring
3

Reopen in Container
VS Code will detect the .devcontainer/devcontainer.json file and show a notification:

“Folder contains a Dev Container configuration file. Reopen folder to develop in a container.”

Click “Reopen in Container”.

Alternatively, open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and select:
Dev Containers: Reopen in Container

4

Wait for the container to build
The first build may take several minutes as Docker downloads the OCaml image and installs tools. Subsequent launches will be fast.

The initial build may take 10–20 minutes depending on your internet speed. Subsequent launches will be much faster due to Docker caching.
💡 Once the container is running, you have a full OCaml development environment with OCaml 5.2 compiler, utop (interactive REPL), dune (build system), ocaml-lsp-server (code completion, type hints, etc.), and ocamlformat (code formatter).
Verify Your Setup

Run these commands in the VS Code terminal (inside the container) to make sure everything works.

🔍

Check OCaml Version

bash
ocaml --version

Expected output: The OCaml toplevel, version 5.2.x

💬

Try the Interactive REPL (utop)

Launch utop for an interactive OCaml session:

bash
utop

Try typing an expression:

ocaml
List.map (fun x -> x * x) [1; 2; 3; 4; 5];;

Expected output: - : int list = [1; 4; 9; 16; 25]

💡 Press Ctrl+D to exit utop.
🎓

Run a Homework File

You can run OCaml files directly or load them in utop:

bash
# Run an OCaml file directly
ocaml hw1/problem1.ml

# Or load it in utop
utop
# Then type:  #use "hw1/problem1.ml";;
📄 Quick Reference

Useful commands for OCaml development.

Command What it does
ocaml file.ml Run an OCaml file directly
utop Start the enhanced interactive REPL with auto-completion
#use "file.ml";; Load a file inside utop
dune build Build the project using Dune
dune exec ./main.exe Build and run an executable
dune test Run tests defined in the project
opam list List installed OCaml packages
opam install <package> Install a new OCaml package
🔧 Troubleshooting

Common issues and how to fix them.

Problem Solution
Docker not running Make sure Docker Desktop is running before opening VS Code.
Container build fails Open the Command Palette and select Dev Containers: Rebuild Container.
Permission issues on Linux Add your user to the docker group: sudo usermod -aG docker $USER, then log out and back in.
opam environment not set Run eval $(opam env) in the terminal.