I've been using Ocaml (and before that, cam-light) for .... decades.  I've always built the compiler+runtime from sources, and have a "BUILD-INSTALL" script, lovingly maintained and updated over the years, to download-and-install ocaml, findlib, oasis, other libraries, and recently, opam too.  I've seen opam's "switch" command, but never used it.  It wasn't obvious to me how to use it, so I just stuck to my old way of doing this sort of setup, every time a new ocaml version came out.

Until today.  Today I decided to figure out how to use "opam switch". And just in case there are other people who are reluctant, I figured I'd document my experience, so others could cut-and-paste.  I'm sure inveterate opam users will just skip past, but I figured, there might be some who still haven't taken the plunge, so hey, here's a crib-sheet.

(1) install "opam" on Ubuntu

  % sudo apt-get install opam

(2) install Ocaml 4.07.1
--------------------------------------------------------------------------------
export VERSION=4.07.1

export OPAMROOT=$HOME/Hack/Ocaml/$VERSION

mkdir -p $OPAMROOT
echo "export OPAMROOT=$OPAMROOT" >> $OPAMROOT/dot.bashrc

opam init --dot-profile=$OPAMROOT/dot.bashrc \
    -j 32 \
    --yes \
    --bare \
    --inplace-build \
    --enable-completion \
    --enable-shell-hook \
    --shell-setup

eval $(opam env)

opam switch create ocaml-base-compiler.$VERSION --repositories=default,beta=git+https://github.com/ocaml/ocaml-beta-repository.git
--------------------------------------------------------------------------------
(2) install the latest beta (4.08.0+beta1)
--------------------------------------------------------------------------------
export VERSION=4.08.0+beta1

export OPAMROOT=$HOME/Hack/Ocaml/$VERSION

mkdir -p $OPAMROOT
echo "export OPAMROOT=$OPAMROOT" >> $OPAMROOT/dot.bashrc

opam init --dot-profile=$OPAMROOT/dot.bashrc \
    -j 32 \
    --yes \
    --bare \
    --inplace-build \
    --enable-completion \
    --enable-shell-hook \
    --shell-setup

eval $(opam env)

opam switch create ocaml-variants.$VERSION --repositories=default,beta=git+https://github.com/ocaml/ocaml-beta-repository.git
--------------------------------------------------------------------------------

And to set up the environment in a shell for each of these installs, just source the dot.bashrc in $OPAMROOT/dot.bashrc

I must say, this is ... *much* easier than "ocamlbrew", and that was already pretty fricken' easy.