Note that you can also use

  opam config exec --switch=<SWITCH> -- <COMMAND>

to execute a command with a local switch choice. This is very helpful in contexts where you don't exactly remember how to setup the environment (eg. when prompted for an in-Emacs compilation command), or you want to play with several versions alternatively in a single terminal (testing a regression in new OCaml versions).

On Fri, Sep 19, 2014 at 9:21 AM, Louis Gesbert <louis.gesbert@ocamlpro.com> wrote:

Le jeudi 18 septembre 2014, 17:20:37 Yotam Barnoy a écrit :

> I have a question about opam. I would like to play with certain compiler

> versions, but I don't want the switch to happen globally, because I still

> need to compile regular code. Is it possible to switch to another compiler

> locally (within a particular shell session) via environment variables,

> while using my regular compiler in another shell session?

>

> If this is the way things work already, I apologize in advance -- it

> appeared to me that running opam switch modifies some global state that

> directly affects other pre-existing shell sessions.

>

> -Yotam

>

>

 

This is already in our new FAQ [1] :)

We're just waiting for 1.2 to be out before we post the new doc pages, because some of it doesn't apply to the current 1.1 stable release. OPAM 1.2 is still in RC stage.

 

 

[1]

http://opam.ocaml.org/doc/1.2/FAQ.html#CanIworkondifferentswitchesatthesametimeindifferentshells