Setting up an OCaml development environment
In this post, I'll describe how I've setup my development envirnoment.
  1. Overview
  2. Installing on Ubuntu
  3. Installing on OSX
  4. OPAM Configuration (Ubuntu and OSX)
  5. Essential Packages
  6. What Editor?
  7. Workflow
  8. Other Tools to be Aware of
  9. Other Libraries to be Aware of

Overview

My development environment looks like this:

  1. Text editor - where I edit code, tests and a Makefile
  2. Shell - where I run make commands and interact with code
  3. Coretop - where I quickly check types and do mini-experiments
Installing on Ubuntu

Install opam (the Ocaml Package manager) via the apt-get command

            sudo apt-get install opam
        
Installing on OSX

Install opam (the Ocaml Package manager) via brew

            brew install opam
        
OPAM Configuration (Ubuntu and OSX)
TL;DR - run the following:
            opam init
        
            opam switch 4.02.3
        
Add the following to your ~/.bashrc (or equivalent):
        eval `opam config env`
        
  1. Initialize opam
                opam init
            
    OPAM will print some introductory information and ask if you would like it to update ~/.bashrc and ~/.ocamlinit for environment configuration. Type 'y'.
  2. Now a default version of the compiler is installed. To view other available compiler versions, run:
            opam switch
        
    To install the latest version of the compiler (4.02.3 as of 2015-10-16), use the following:
            opam switch 4.02.3
        
    To change your path to the newly built compiler, run:
            eval `opam config env`
        
    I recommend adding this to your ~/.bashrc or equivalent.

Essential Packages

TL;DR - three packages are essential: core, ounit and utop
        opam install core ounit utop
    
OCaml comes with a standard library that is kept small. There are several alternatives open-source standard libraries that are easily installable. The first is Jane Street Core.
        opam install core
    
The other primary library (that I know of) is Batteries
        opam install batteries
    
I prefer Core over Batteries (as do the authors of Real World OCaml). After you've installed a better standard library, I recommend installing OUnit, a testing framework.
        opam install ounit
    
Finally, while OCaml comes with a repl, "top", there is a better version available: utop. Core + utop will actually give you an even better REPL: coretop. coretop is utop except that it already knows about the Core library.
What Editor?

I personally prefer Sublime with vim keybindings.

Workflow

TL;DR -don't call ocamlc directly; use ocamlbuild with -use-ocamlfind TARGET.byte

Use Makefiles to automate steps of workflow. See here for an example of both.

An OCaml installation comes with two versions of the compiler: ocamlc and ocamlopt. ocamlc generates byte code, whereas ocamlopt generates a native binary. I recommend using ocamlbuild for building your projects. It can manage dependencies and pick the appropriate compiler. Example: suppose I have a file named foo.ml, the module interface is in foo.mli and it uses the Core library. The following commands will, respetively build bytecode and native binaries:
        camlbuild -use-ocamlfind foo.byte
    
        camlbuild -use-ocamlfind foo.native
    
I typically try to divde my project into separate modules, each with their own directory, Ocaml module, tests and Makefile. Makefiles are very useful for quickly invoking different commands in the OCaml toolchain. I've provided an example Makefile I use as a gist
Other Tools to be Aware of Here are some cool sounding tools I'm aware of, but have not yet taken the time to use.
  1. Merlin - From the site: "Merlin is an editor-independent tool to ease the developpement of programs in OCaml"
  2. Bisect - a code coverage tool for OCaml
  3. OCamldoc - Generate documentatio from appropriately commented code

Other Libraries to be Aware of Here are some cool sounding libraries I'm aware of, but have not yet taken the time to use.
  1. OCamlnet - a suite of utilities for working with internet protocols (http, cgi, email, etc).
  2. Mirage OS - a project to run OCaml code on the Xen hypervisor without need of a guest OS.
  3. Irmin - Git like data storage; support in-memory, flat file, or actual git format.