Skip to content

Instantly share code, notes, and snippets.

@mnxn
Last active March 2, 2024 01:53
Show Gist options
  • Save mnxn/93009346c1bd56f387daf28413152179 to your computer and use it in GitHub Desktop.
Save mnxn/93009346c1bd56f387daf28413152179 to your computer and use it in GitHub Desktop.
OCaml on MSYS2 (outdated)
  1. Install MSYS2

  2. Install required packages:

$ pacman -S rsync patch diffutils curl make unzip git m4 perl tar mingw-w64-cross-gcc mingw-w64-x86_64-pkg-config
  1. Add /opt/bin to $PATH:
$ echo 'export PATH=$PATH:/opt/bin' >> ~/.bashrc
  1. Restart the terminal or do source ~/.bashrc

  2. Download and extract the opam64 archive

$ curl -LO https://github.com/fdopen/opam-repository-mingw/releases/download/0.0.0.2/opam64.tar.xz
$ tar xf opam64.tar.xz
  1. Run the opam install script. Ignore the messages about missing programs. MSYS2 installs packages differently from Cygwin.
$ bash opam64/install.sh
  1. Initialize the opam repository and set a default switch.
$ opam init default "https://github.com/fdopen/opam-repository-mingw.git#opam2" -c "ocaml-variants.4.10.0+mingw64c" --disable-sandboxing
  1. Allow opam to edit .bash_profile. (Press y)
Do you want opam to modify C:/dev/msys2/home/Max/.bash_profile? [N/y/f]
(default is 'no', use 'f' to choose a different file) y
  1. Allow opam to add the hook. (Press y)
A hook can be added to opam's init scripts to ensure that the shell remains in sync with the opam environment when they are loaded. Set that up? [y/N]
  1. Restart the terminal and you are ready to use OCaml in MSYS2.
@florianingerl
Copy link

Hello,
I could follow the instructions above up to point 6.
If I run the command $ bash opam64/install.sh
I get the error message
$ bash opam64/install.sh
warning: git not installed. opam will not work without it!
warning: unzip not installed. opam will not work without it!
warning: rsync not installed. opam will not work without it!
warning: patch not installed. opam will not work without it!
warning: diffutils not installed. opam will not work without it!
warning: make not installed. opam will not work without it!
warning: m4 not installed. opam will not work without it!
warning: neither curl nor wget are installed!
pleas install at least on of them
please install either mingw64-i686-gcc-core (32-bit) or mingw64-x86_64-gcc-core (64-bit)
you need a working C compiler to compile native ocaml programs
the following programs are not installed properly:
tar / xz
I can't proceed :(

I tried to make the "git is not installed message disappear" by running "pacman -S git" first, which worked fine. But the error message doesn't disappear. I run all this from the MSYS2 MinGW x64 console.

@florianingerl
Copy link

I checked whether git is really installed with the command
"git --version" which gave "git version 2.43.2"

@mnxn
Copy link
Author

mnxn commented Feb 17, 2024

These instructions are very old, so it's entirely possible that they don't work anymore.

If you're just trying to install OCaml on Windows follow the official instructions here: https://ocaml.org/docs/ocaml-on-windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment