Opam switch: reinstall packages from another switch

I want to create a new switch for OCaml 4.11.0. The current switches I have contain packages that I’d like to use in 4.11.0. Is there a way to instruct opam to automatically install those packages in the new switch? For example, when upgrading my Node.js installation using nvm, I can pass the --reinstall-packages-from=v10.0 argument to do what it says on the tin.

If you go to your earlier switch and export its package list with opam switch export packages-list (‘packages-list’ here being the file to which the list will be exported, you can give it any name you like), you can then go to your 4.11.0 switch and recompile/install them for that switch with opam switch import packages-list. This is how I do it but this goes back a way: I have half a recollection that opam is intended to provide new functionality to make updating of this kind easier, but I don’t know if it has landed yet.

1 Like

I hope it lands soon. It would be nice to upgrade only the compiler and have the local packages rebuilt without pulling them from the internet.

They won’t be repulled if you haven’t cleaned your opam installation. They should still be around.

1 Like

Yes, most of them were already in the cache. This works.