How to install ocaml on Mac

I’m using HomeBrew right now to install it, and so far the process is going much smoother.

https://gyazo.com/009c5dd390a596475ab5dada04091214
https://gyazo.com/722a2a5f46628d03e7ae23a25a8faa3b
Where do I go from here?

Using brew is usually pretty reliable for me.

brew install opam
opam init
eval `opam config env`
opam switch 4.06.1

I just received a work laptop which is a Mac running OSX and the above worked for me.

1 Like

Okay, running that now.

https://gyazo.com/6947a469486d2f8f58173db6410fe005

I would go ahead and check out the documentation for opam. The switch command will give you a sandboxed version of the ocaml compiler, and you can also use opam to install packages that you need later on.

Your first call to brew install opam install opam was malformed. It needs to be just brew install opam. Then you should be able to follow the remainder of the steps:

opam init
eval `opam config env`
opam switch 4.06.1


This is where I have ended up after using the above commands:

brew install opam

then

opam init
eval opam config env
opam switch 4.06.1

From your gif it looks like you are entering multiple commands on the same line. Each line above denotes one command. Try to execute each command individually.

i.e.

opam init <ENTER>
eval opam config env <ENTER>
opam switch 4.06.1 <ENTER>

Okay, currently running the last command.

https://gyazo.com/dbc42502a9ce58b59f85caa325294ed4

This is where I am now, after running those commands.

Looks to me like you are done!

So I can code straight into terminal now, or is there an application I should be looking for at this point? Thanks for the help.

If you want to play with the language, I would recommend:

opam install utop

which will install a very nice interpreter for ocaml. Then you can do:

utop

and start typing in OCaml expressions:

utop # 1 + 4;;
- : int = 5

For compiling OCaml applications I would recommend the dune build system.

1 Like

See also: https://dev.realworldocaml.org/install.html

If you just want to see if your OCaml toplevel is working you can do a quick test from the terminal:

$ ocaml
        OCaml version 4.06.0
# 1 + 4;;
- : int = 5
# exit 0;;
$

(The ;; token tells the toplevel to evaluate what you’ve typed since the last evaluation.)

1 Like

hi, can you help me? I use Mac with the system 10.13.6. But I can’t install Graphics package, how can I install it? I have tried lots of methods, but failed…thanks

how does one make sure one has installed the newest version of ocaml?

Install any version of opam you like (from brew or macports) and then you can use opam to build the latest release version (which is 4.08.1).