Document how opam chooses the default compiler during opam init and opam switch create - #6778
Open
kit-ty-kate wants to merge 1 commit into
Open
Document how opam chooses the default compiler during opam init and opam switch create#6778kit-ty-kate wants to merge 1 commit into
kit-ty-kate wants to merge 1 commit into
Conversation
…pam switch create
dra27
reviewed
Nov 10, 2025
dra27
left a comment
Member
There was a problem hiding this comment.
Perhaps the FAQ isn't the correct place to be noting opam switch create 5.4 ocaml.5.4.0, but it would go well with the part about opam init --compiler (i.e. that you can just specify the precise version package and not rely on any of these heuristics)
Comment on lines
+445
to
+449
| Since opam 2.4, `opam init` will choose `ocaml-base-compiler` as default | ||
| compiler for the `default` switch, and let the solver choose the latest | ||
| version. Of course this default can always be changed using `--compiler` | ||
| or by skipping the creation of the `default` switch all-together with | ||
| `--bare`. |
Member
There was a problem hiding this comment.
Suggested change
| Since opam 2.4, `opam init` will choose `ocaml-base-compiler` as default | |
| compiler for the `default` switch, and let the solver choose the latest | |
| version. Of course this default can always be changed using `--compiler` | |
| or by skipping the creation of the `default` switch all-together with | |
| `--bare`. | |
| Since opam 2.4, `opam init` will select `ocaml-base-compiler` as the default | |
| compiler package for the `default` switch, and let the solver choose the latest | |
| version. This can always be changed using `--compiler` or by skipping the | |
| creation of the `default` switch altogether with `--bare`. |
| `--bare`. | ||
|
|
||
| For example if you would rather use the OCaml compiler that you have | ||
| installed by other means, you can use the `ocaml-system` package as follows: |
Member
There was a problem hiding this comment.
Suggested change
| installed by other means, you can use the `ocaml-system` package as follows: | |
| installed outside opam, you can use the `ocaml-system` package as follows: |
?
Comment on lines
+451
to
+456
| For example if you would rather use the OCaml compiler that you have | ||
| installed by other means, you can use the `ocaml-system` package as follows: | ||
| `opam init --compiler=ocaml-system`. Be careful though, system-wide compilers | ||
| can be setup in a way that the default opam-repository doesn't expect, | ||
| so failures may occur. Thus this option should only be used if you know | ||
| what you're doing. |
Member
There was a problem hiding this comment.
Suggested change
| For example if you would rather use the OCaml compiler that you have | |
| installed by other means, you can use the `ocaml-system` package as follows: | |
| `opam init --compiler=ocaml-system`. Be careful though, system-wide compilers | |
| can be setup in a way that the default opam-repository doesn't expect, | |
| so failures may occur. Thus this option should only be used if you know | |
| what you're doing. | |
| For example, if you would rather use the OCaml compiler that you have | |
| installed by other means, you can use the `ocaml-system` package as follows: | |
| `opam init --compiler=ocaml-system`. Be careful, though; system-wide compilers | |
| can be set-up in a way that the default opam-repository doesn't expect, | |
| so failures may occur. Thus this option should only be used if you know | |
| what you're doing. |
| installed by other means, you can use the `ocaml-system` package as follows: | ||
| `opam init --compiler=ocaml-system`. Be careful though, system-wide compilers | ||
| can be setup in a way that the default opam-repository doesn't expect, | ||
| so failures may occur. Thus this option should only be used if you know |
Member
There was a problem hiding this comment.
Suggested change
| so failures may occur. Thus this option should only be used if you know | |
| so failures may occur. We recommend this option should only be used if you know |
?
Comment on lines
+458
to
+459
| `opam switch create <version>` on the other hand, works slightly differently. | ||
| Since the only unknown is: which package is going to be used. |
Member
There was a problem hiding this comment.
Suggested change
| `opam switch create <version>` on the other hand, works slightly differently. | |
| Since the only unknown is: which package is going to be used. | |
| `opam switch create <version>` on the other hand, works slightly differently, | |
| since the only unknown is exactly which package is going to be used. |
Comment on lines
+460
to
+467
| Opam decides this by looking at all the packages that have been tagged as | ||
| `compiler`, filter which ones have the right version, and then let the solver | ||
| decide. For example calling `opam switch create 5.4 5.4.0` will create a | ||
| switch named `5.4` and look for compiler packages with versions `5.4.0` which | ||
| by default, with [opam-repository](https://github.com/ocaml/opam-repository/), | ||
| will get back with `ocaml-base-compiler.5.4.0` and `ocaml-system.5.4.0`. | ||
| Since 2025, `ocaml-system` is tagged as `avoid-version` so the solver will | ||
| choose `ocaml-base-compiler.5.4.0`. |
Member
There was a problem hiding this comment.
Suggested change
| Opam decides this by looking at all the packages that have been tagged as | |
| `compiler`, filter which ones have the right version, and then let the solver | |
| decide. For example calling `opam switch create 5.4 5.4.0` will create a | |
| switch named `5.4` and look for compiler packages with versions `5.4.0` which | |
| by default, with [opam-repository](https://github.com/ocaml/opam-repository/), | |
| will get back with `ocaml-base-compiler.5.4.0` and `ocaml-system.5.4.0`. | |
| Since 2025, `ocaml-system` is tagged as `avoid-version` so the solver will | |
| choose `ocaml-base-compiler.5.4.0`. | |
| Opam decides this by finding all packages which have the given and which | |
| that have been flagged as `compiler` and then presents just these packages | |
| to the solver. For example calling `opam switch create 5.4 5.4.0` will create a | |
| switch named `5.4` and look for compiler packages with versions `5.4.0` which | |
| by default, with [opam-repository](https://github.com/ocaml/opam-repository/), | |
| will be with `ocaml-base-compiler.5.4.0`, `ocaml-system.5.4.0` and | |
| `ocaml-variants.5.4.0+options`. `ocaml-system.5.4.0` is flagged as `avoid-version`, | |
| so the solver will choose `ocaml-base-compiler.5.4.0`. |
(although I can't remember for certain why ocaml-base-compiler.5.4.0 is guaranteed to be selected, given that it actually has more dependencies than ocaml-variants.5.4.0+options)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6407