A slightly different take, whichs ends up with a similar solution to @Bryson's answer but the way to get there may be more general and helpful to more people. Also, I disagree with the statement that the proper way to do this is to use the
--ignore-dependencies flag. When you use that flag is says
--ignore-dependencies is an unsupported Homebrew developer flag!
Adjust your PATH to put any preferred versions of applications earlier in the
PATH rather than using this unsupported flag!
Additionally I don't like that solution because you have to remember to manually check the dependencies of everything you install going forward, and manually do the work of installing all of those dependencies other than the one you want to avoid. I think that's a pretty bad solution.
The warning actually contains a suggestion for how to fix the problem; adjust your path variable. I ran into this with Java, not OCaml, but the solution should be the same for any software.
brew puts executables into
/usr/local/bin/ so the directory with the executable of the dependency which you want to use must be earlier in your path than
/usr/local/bin/. So I check what Java executable is being used
$ which java
And I check my path to see where that is relative to
$ echo $PATH | tr ':' '\n'
I could change the order of those in my
.bash_profile but I actually want to keep that order, so instead I'm going to create a symlink in
/usr/local/bin to point to the executable of the dependency in
/usr/bin then brew will be able to see my version of the depedendency at the same level as all the other brew dependencies.
$ ln -s /usr/bin/java /usr/local/bin/java
Now brew will not try to install a different version of Java, or whatever dependency you are dealing with.