# Using flambda2 with opam

**URL:** <https://discuss.ocaml.org/t/using-flambda2-with-opam/16803>\
**Category:** Learning\
**Tags:** opam\
**Created:** [June 13, 2025, 5:19am UTC](https://discuss.ocaml.org/t/using-flambda2-with-opam/16803 "2025-06-13T05:19:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joelreymont](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/joelreymont/32/5937_2.png) [@joelreymont](https://discuss.ocaml.org/u/joelreymont)\
**Post date:** [June 13, 2025, 5:19am UTC](https://discuss.ocaml.org/t/using-flambda2-with-opam/16803/1 "2025-06-13T05:19:37Z")

</div>

I built 0xCaml (flambda2) on macOS and installed it under `/usr/local`.

How do I create a switch for opam with my locally built ocaml?

It seems that opam sets up zsh hooks and I can’t just put `/usr/local/bin` at the beginning of `$PATH` anymore since opam puts itself there.

It seems I can `opam switch create ocaml-local --empty` but how do I tell dune to use my local compiler? `opam install dune` pulls in the standard ocaml 5.2 compiler and dune then proceeds to use that.

---

<div class="post-metadata">

**Author:** ![joelreymont](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/joelreymont/32/5937_2.png) [@joelreymont](https://discuss.ocaml.org/u/joelreymont)\
**Post date:** [June 13, 2025, 6:39am UTC](https://discuss.ocaml.org/t/using-flambda2-with-opam/16803/2 "2025-06-13T06:39:08Z")

</div>

Jane St has [instructions for installing flambda2 using opam](https://github.com/janestreet/opam-repository/tree/with-extensions). You can use [this repo](https://github.com/gridbugs/hello-oxcaml/tree/with-custom-patch) to test if it’s working.

I’m still scratching my head about using a locally built version. There’s [helpful information available](https://github.com/ocaml/platform-blog/blob/6242bcd5fc1b301ee05be0fd544f6b6fe2581839/opam-20-tips-compilers.md) but I wasn’t able to take advantage of it.

---

<div class="post-metadata">

**Author:** ![vlaviron](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vlaviron](https://discuss.ocaml.org/u/vlaviron)\
**Post date:** [June 13, 2025, 8:47am UTC](https://discuss.ocaml.org/t/using-flambda2-with-opam/16803/3 "2025-06-13T08:47:35Z")

</div>

In general, if you want to create a switch with a locally-built compiler you need to use the `ocaml-system` package. But my experience with it is not great, so I would advise using the official way; with manual editing of the opam package if you really want to use a non-release version (`opam pin edit ocaml-variants.5.2.0+ox`, you can change the `url` field to point to something else like a git branch).
