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

2 Likes

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.

3 Likes

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.

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

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

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.

3 Likes