At least something similar to that, I’m on mobile right now so I can’t check. But I did this recently and it should upgrade and rebuild all packages as necessary.
why would you want to delete the old switch? Just create a new one, use “opam list” to get a list of installed packages, a little perl magic to get the list of names and nothing else, and do an “opam install” with that list in the new switch context ?
I have … 29 switches installed: basically every installable version of OCaml from 4.02.0 thru 4.13.0~alpha02 .
@OCamlUser command is good, for opam 2.0 ; for 2.1, the option is --update-invariant.
If you don’t want to update manually your compiler, with 2.1 you can automate it. It introduces switch invariants, a package formula which must be satisfied on every upgrade and install.
You can define your switch invariant as ocaml with no version to have always the most up-to-date (including variants), or ocaml-base-compiler to have only OCaml releases.
opam switch set-invariant ocaml-base-compiler
Once that done, you will have the latest OCaml compiler at each upgrade.
You can also do opam switch export [filename] to put the current list into a file by the name of ‘filename’, and then in the new switch do opam switch import [filename] to install the packages in the new switch.
My 2c on a local workflow. I don’t migrate switches between compiler version I
just create a new one, relying on opam files to know their dependencies and will
add them if they’re missing. Similar to @mudrz
# Create the new switch appending project name eg thrift
opam switch create 4.10.1-thrift 4.10.1
# Use direnv to automatically switch to the projects switch
echo "use ocaml 4.10.10-thrift" > .envrc
# Install the dependencies as per the opam file, something like
opam depext -yt thrift
opam install --deps-only -td .
# Install various pieces like merlin/lsp/ocamlformat cause they're usually not included in opam files as a dependency.
# Throw away the old switch when my SSD is full.
Many of these steps should be easier and more streamlined, driven off the existing config in opam / dune.