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 .
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.