How to install OCaml 5.00.0+trunk using opam?

I’m hoping to play around with multicore, but I’m quite stuck trying to install OCaml 5, and searching hasn’t been able to turn up any set of clear instructions detailing how to create a switch for this purpose. I’m hoping someone who knows better can help unblock me and offer instructions for other curious users.

I’m trying:

$ opam switch create .  5.00.0+trunk
[ERROR] Could not resolve set of base packages:
        The following dependencies couldn't be met:
          - ocaml-variants → ocaml-beta
              unmet availability conditions: enable-ocaml-beta-repository

So I then ensure that the ocaml-beta package is installed:

$ opam install ocaml-beta
[NOTE] Package ocaml-beta is already installed (current version is enabled).

With the details:

$ opam info ocaml-beta

<><> ocaml-beta: information on all versions ><><><><><><><><><><><><><><><><><>
name                   ocaml-beta
all-installed-versions enabled [ocaml-base-compiler.4.13.1]
all-versions           disabled  enabled

<><> Version-specific details <><><><><><><><><><><><><><><><><><><><><><><><><>
version      enabled
repository   ocaml-beta
homepage:    "https://ocaml.org"
bug-reports: "https://github.com/ocaml/ocaml/issues"
authors:     "Xavier Leroy"
             "Damien Doligez"
             "Alain Frisch"
             "Jacques Garrigue"
             "Didier Rémy"
             "Jérôme Vouillon"
maintainer:  "platform@lists.ocaml.org"
synopsis     OCaml beta releases enabled
description  Virtual package enabling the installation of OCaml beta releases.

This was due to me having already enabled opam-beta by following the instructions on the package, and opting to enable it for all switches.

I’ve tried the other command given in the package too:

$ opam switch create ocaml-beta --repositories ocaml-beta=git+https://github.com/ocaml/ocaml-beta-repository.git
[ERROR] No compiler matching 'ocaml-beta' found, use 'opam switch list-available' to see what is available, or use '--packages' to select packages explicitly.

And I’ve tried various variations thereof:

$ opam switch create . 5.00.0+trunk --repositories ocaml-beta=git+https://github.com/ocaml/ocaml-beta-repository.git
[ERROR] No compiler matching '5.00.0+trunk' found, use 'opam switch list-available' to see what is available, or use '--packages' to select packages explicitly.
$ opam switch list-available --repositories ocaml-beta=git+https://github.com/ocaml/ocaml-beta-repository.git
# Listing available compilers from repositories: ocaml-beta
# No matches found

:woman_shrugging:

Thank you in advance for the help!

you need both the default and the beta repos. default where ocaml-variants exists, and beta to enable trunk variants.
opam switch create . 5.00.0+trunk --repos beta,default

1 Like

That’s interesting. I don’t have the beta repository enabled, but the following works for me

$ opam repo
[NOTE] These are the repositories in use by the current switch. Use '--all' to see all configured repositories.

<><> Repository configuration for switch ocaml.4.13.1 <><><><><><><><><><><><><>
 1 default https://opam.ocaml.org

$ opam switch create 5.00.0+trunk

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: ["ocaml-variants" {= "5.00.0+trunk"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed base-bigarray.base
-> installed base-threads.base
-> installed base-unix.base
-> retrieved ocaml-variants.5.00.0+trunk  (https://github.com/ocaml/ocaml/archive/trunk.tar.gz)
-> installed ocaml-variants.5.00.0+trunk
-> installed ocaml-config.2
-> installed ocaml.5.00.0
-> installed base-domains.base
-> installed base-nnp.base
Done.
# Run eval $(opam env --switch=5.00.0+trunk) to update the current shell environment
2 Likes

Thanks for the tip, @hyphenrf! I think that sorted me out. To summarize:

Upgrade to opam >= 2.1

As of opam 2.1, installing trunk switches is no different than installing other switches. So if you’re having trouble, best to just upgrade opam.

Thanks, @kit-ty-kate !

With opam < 2.1

Installing OCaml 5.00.0+trunk from a switch without ocaml-beta enabled

It seems the complete invocation to bring a user on a switch without ocaml-beta enabled onto a newly created switch for the current directory, running 5.00.0+trunk should be:

opam repository add ocaml-beta git+https://github.com/ocaml/ocaml-beta-repository.git
opam switch create . 5.00.0+trunk --repos beta,default

General recipe for creating trunk switches

More generally, the recipe for installing any trunk switch from a switch that does not have ocaml-beta enabled should be:

opam repository add ocaml-beta git+https://github.com/ocaml/ocaml-beta-repository.git
opam switch create <SWITCH-NAME> <VERSION>+trunk --repos beta,default

I couldn’t find this recipe clearly indicated anywhere online. It’s only two lines, but there are around 10 non-obvious elements to the invocation, so it’s worth making this clearly documented somewhere I think.

I’ll create a SO question for it. Where else should these recipe be documented for users? Do people know of places that already document this that they could link from here?

1 Like

hey just one thing: since you named it ocaml-beta in your opam repos, then your invocation would be ocaml-beta,default.

; ocaml -vnum
5.00.0+dev0-2021-11-05
; opam rep
[NOTE] These are the repositories in use by the current switch. Use '--all' to
       see all configured repositories.

<><> Repository configuration for switch trunk ><><><><><><><><><><><><><><><><>
 1 multicore git://github.com/ocaml-multicore/multicore-opam.git
 2 alpha     git://github.com/kit-ty-kate/opam-alpha-repository.git
 3 beta      git://github.com/ocaml/ocaml-beta-repository.git
 4 default   https://opam.ocaml.org

and btw --repos is just short for --repositories. opam (and dune) allows any unambiguous prefix to be a shortcut for its full-length name, I have no idea why this isn’t the standard for all CLI tools… it’s so good.

as for where this recipe is outlined, I think I first picked it up from a release candidate announcement here on discuss.

1 Like

That’s because with opam >= 2.1 it works out-of-the-box without ocaml-beta-repository

2 Likes

I guess this may also explain why there aren’t some stable, authoritative docs on the process for old opam versions. I didn’t realize I’d fallen out of date :slight_smile: