How does one check the ocaml version one is using?

Seems this question is not as simple as I thought. Probably because there is a toplevel and a compiler. I can’t seem to have the toplevel to be the version I want but I’ve been successfully able to switch between compiler version.

Check the session where I try switching version but the toplevel doesn’t change but the compiler does.

(base) ❯ opam switch list
#  switch   compiler                    description
→  4.05.0   ocaml-base-compiler.4.05.0  4.05.0
   4.06.0   ocaml-base-compiler.4.06.0  4.06.0
   4.07.0   ocaml-base-compiler.4.07.0  4.07.0
   default  ocaml-system.4.07.0         default
(base) ❯ opam switch 4.06.0
(base) ❯ ocaml --version
The OCaml toplevel, version 4.07.0
(base) ❯ opam switch list
#  switch   compiler                    description
   4.05.0   ocaml-base-compiler.4.05.0  4.05.0
→  4.06.0   ocaml-base-compiler.4.06.0  4.06.0
   4.07.0   ocaml-base-compiler.4.07.0  4.07.0
   default  ocaml-system.4.07.0         default

So my question here is what are all the commands to check all ocaml versions running, toplevel, compiler etc? (idk if there are more things I should be aware of hence the etc).


related questions:

# to synchronize your environment with opam
# (assuming your are using the bash shell)
eval `opam env --shell=bash`
# interpreter version
ocaml --version
The OCaml toplevel, version 4.07.1
# compiler version
ocamlc --version
4.07.1
1 Like

what does it mean “to synchronize your environment with opam”? like for example, how can I see they are not synchronized?

After some opam commands, you need to update some env. variables.

eval `opam env --shell=bash`

I don’t know how you can detect that your environment is out of sync (some things
stop working, or are using a different compiler version than the one you want).
By using eval, you force the environment to be updated.