Using OCaml compiler from external drive

I have a machine with limited space. I have an external ssd so I can work with OCaml/ReasonML native compilation projects.

How would I use opam/ocaml from this disk so it doesnt eat up my primary limited hard drive space?

Thank you.

On Linux and macOS you can mount the drive to your .opam.

If it’s a subfolder of your drive you can use mount --bind


You can also set the OPAMROOT variable to something that points to your SSD. It will be used as the “opam root” instead of $HOME/.opam.


Very helpful gentleman. Thank you.

For the record, these are the commands I have run to get my opam and esy setup on the external ssd.

 [I] ➜ set -xg ESY__PREFIX /Volumes/external/.esy
 [I] ➜ echo $ESY__PREFIX

 [I] ➜set -xg OPAMROOT /Volumes/external/.opam
~/Downloads took 2m 52s 87ms
 [I] ➜ echo $OPAMROOT

Then run opam init per instructions.

Running esy in projects is using the external ssd %EXTERNAL/.esy for caching. Opam is use .opam in same.

Thanks again.