To install OCaml and libraries, we will use OPAM, which is the OCaml ecosystem's package manager.
We strongly recommend using a text editor that you are not also using for a class or personal project that makes use of coding agents. This may mean learning how to use a different text editor. Please consider this an exciting opportunity to try something out. We will provide advice for multiple text editors for this purpose.
This guide from ocaml.org provides a tutorial walk through for installing OCaml. But before working through this general setup, please read on for specific instructions we believe will suffice for CSE 341. Please speak up on the discussion board if you run into problems after following these steps carefully, so we can improve these notes. If they don't make sense, please ask!
Warning! If the following installation goes horribly wrong, please skip to the end of this page. There are some alternate approaches listed there. If you go this route, please also post on the discussion board so we can try to help you get a working local installation.
Finally, we always do our best to try to get everyone's submissions working. However, for the sake of our sanity and yours, we will ultimately use the attu servers (see end of this guide) to determine whether or not your code is working correctly.
Here is what we have found to work:
Follow these instructions to install the Windows Subsystem for Linux (WSL).
WSL allows Windows developers to run a GNU/Linux-like environment directly on Windows without the overhead of a traditional virtual machine or dual-booting setup. We will generally assume that all students have access to a Unix shell, so this is the best approach.
Install WSL 2 if possible.
To install make and cc, run this command:
sudo apt install build-essential
Now follow the Linux, MacOS, and WSL instructions below.
Follow the instructions from the OCaml for Windows project's page on installing opam on Windows.
The 64-bit graphical installer is probably what you want.
If you get a virus-scan failure on the graphical-installer download, try "save link as" from an incognito browser window.
After installation completes (it takes a while), open the cygwin shell created in the previous step, called something like cygwin64 Terminal, and proceed to step 2.
Note: If you already had cygwin installed, you now have a second one installed. This is no problem, but you will need to keep track of "which is which" and open a terminal for the cygwin you just created here for the instructions that follow and whenever opening vscode. (Again, we strongly recommend using WSL instead)
Follow the instructions on the official OPAM installation page with these caveats:
On Mac, you need to have the Xcode command line developer tools installed. There is a good chance you have set this up already, but if not you can install them using:
xcode-select --install
On WSL, you need to have unzip installed and sandboxing disabled
If unzip is not installed, install it with the following command
sudo apt-get install unzip
To disable sandboxing, run the following command
opam init --disable-sandboxing --reinit
It is also possible to install OPAM directly from your preferred OS package manager. For instance, your instructor used Homebrew on his Mac to install opam. Ubuntu and WSL users can turn to apt. If you run a different Linux distro, you definitely don't need this bullet. If this bullet is confusing to you, we recommend simply following the instructions to download a binary installer from the OPAM website.
Once opam is installed, install dune and utop by running this command:
opam install dune utop
If you get an error in the previous step of the form, " [ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch", there are various workarounds, but this has worked for people (note in the future the ocaml version number may be different, but this is sufficiently current as of September 2026).
First run this command:
opam switch create ocaml-base-compiler.5.4.0
Then again try:
opam install dune utop
If you plan to use fancy IDE features for OCaml in VS-Code or another IDE (see more below), you will also want to have the ocaml-lsp-server installed, so run this command:
opam install ocaml-lsp-server
You can learn more about managing your opam installation from the opam usage guide, but you don't need to. If you really like OCaml and want to continue using it, then this is a good idea, but otherwise, let's be real. You don't need to learn a bunch more gobbledigook.
You can do either or both of the following things. Neither are necessary.
By default, utop presents a lot of information that can be more distracting than helpful in a class where we are focusing on fundamentals. We can remove most of this "clutter" as follows:
In your home directory (at a terminal, type cd then the return key to get to your home directory), make a directory .config (notice the period as the first character of the directory) with the command mkdir .config).
Then inside that directory make a directory utop (you can do mkdir .config/utop).
In .config/utop, make a file named init.ml (you can do this from your text editor. You can also use touch .config/utop/init.ml to create an empty file)
Make the contents of init.ml exactly these two lines:
#utop_prompt_dummy;;
UTop.set_show_box false
By default, utop doesn't syntax highlight (use colors). This is not a big deal since we do not tend to write a lot of code directly in utop, but you can get syntax highlighting as follows:
In your home directory (at a terminal, type cd then the return key to get to your home directory), make a file named .utoprc. In that file, you can use content like the following. These colors will work well for "light mode" but won't work well for "dark mode". Caveat emptor!
profile: light
identifier.foreground: none
module.foreground: x-forestgreen
comment.foreground: x-firebrick
doc.foreground: x-violetred4
constant.foreground: x-darkcyan
keyword.foreground: x-darkslateblue
symbol.foreground: x-purdarkslateblueple
string.foreground: x-violetred4
char.foreground: x-violetred4
quotation.foreground: x-darkslateblue
error.foreground: red
directive.foreground: x-mediumorchid4
parenthesis.background: light-blue
It doesn't matter ultimately which text editor you want to use. Your instructor is a stubborn person who has always used fairly minimal text editors with few IDE features for 2 decades. He did not first learn to program this way, but he learned a lot more about programming this way. For this reason, we want to give you many possible options, rather than funnelling you all into using one single blessed text editor.
Beware! Both vim and emacs have somewhat steep learning curves. If you don't have the time to invest in learning this curve, you may want to go with another option. That said, it is very useful to learn at least one of these two editors, even if they do not become your primary editor. After you've SSH'ed into a remote Unix server, you're nearly always guaranteed to have these text editors installed. So, minimal facility with such text editors lets you solve various small problems as a programmer.
vim — Your instructor in this class is using plain old vim from the terminal when you see him coding in class. There are many cool extensions and settings that can make this approach more modern and ergonomic. If you like vim, you may want to try Neovim (see below).
emacs — This is the other classic option. It uses more complex shortcut commands. On Mac, there is a neat version called Spacemacs.
ed — It is universally available. Do not use this. You can get a lot of laughs from your professors and other programmers by saying ed is your favorite text editor.
Sublime Text — This is a surprisingly good and simple text editor. You can set up syntax highlighting, a filesystem tree view and get a lot of other rudimentary features of IDEs without taking on the baggage of relying on a language server. (i.e. that lsp package installed from OPAM earlier in this guide) Your instructor uses this editor as his go to text editor for most things code-related.
Neovim — For those unfamiliar with Vim-style editing, see this guide by RedHat. If using Windows, it is preferable that you use WSL in order to use Neovim.
VSCode — This is the probably the most popular fancy IDE for Allen School undergrads. Read on for how to set up all the bells and whistles. However, please make sure you have coding agents (e.g. copilot) disabled if using this option
We will assume that you can find the installers for VSCode and get the binary installed.
If you are using WSL, you will want to follow these instructions to ensure that VSCode can access WSL.
Install the OCaml Extension: clicking the big green button at the top of this page will install the extension for you in VSCode. Great, you're good to go!
We recommend against using Cygwin. However, if you use Cygwin, then you must open VS Code from inside the Cygwin terminal, not by clicking the VS Code icon.
Every time you want to open VS Code, instead you should open Cygwin terminal and run this command:
/cygdrive/c/Users/Frank\ Smith/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe
The department attu servers (running Linux) have an installation of ocaml. You can ssh into these machines and run code there. (I confirmed the ocaml version was 5.2.0 on Sept. 29, 2026. This version should be fine for the class.)
This installation does not have utop installed by default, but it is sufficient to run code (using the ocaml command). If you want these tools available to you on the department machines, accessed in person or over SSH, then continue with the following instructions:
Run opam init to install a brand new version of ocaml in your department directory.
Now, you can opam install ... as suggested in Step 2 of this guide. Installing utop, dune, etc. will get you access to those tools on the department machines now.
The UW CSE Virtual Machine is a CentOS Linux set up to approximate the set up on Allen School lab computers. Roughly speaking, it will let you run a fresh, full-fledged Linux machine as if it was just another application. If you are struggling to set up software on your personal computer, you may have better luck by:
Setting up the UW CSE VM and then
Following the installation instructions for Linux above.