Start Hacking in OCaml in 5 Steps
We love OCaml at Skydeck, as Jake has written about before, and we often hear from programmers with questions and comments about it. Some love OCaml, some don’t know anything about it, but many have it on their list of languages to try yet haven’t gotten around to it. Well, it’s pretty simple to get up and running — just download, build, and start hacking!
Really, it’s that simple. If you want to get there as quickly as possible, follow these five steps:
1. Download OCaml and unpack it
Get the “Source distribution for Windows and Unix systems”. You could download the binaries directly, but OCaml is really easy to build and you’ll appreciate having the source later. I also like having the PDF version of the User’s manual. If you’re running Windows, you’ll need to install Cygwin.
2. Build and install
The instructions to build are detailed in the INSTALL file that comes with the distribution. Here’s what we do (note all paths are relative to the directory where you unpacked OCaml):
- Configure your system. Fortunately, the distribution comes with a script to help you figure out whether you have the proper tools installed. If you’re missing anything, you’ll need to install it. That’s outside the scope of this post, but most Linux distributions come with package managers to make this easy (e.g. on Fedora, you use yum).
$ ./configure
- Build the distribution. OCaml can build bytecode and native code targets, and we build the compilers necessary for both by running:
$ make world.opt
- Install OCaml. The previous two steps can be run as a regular user, but the install step must be run as root (or via sudo). If you’re running with Cygwin under Windows, don’t worry about it.
# make install
3. Setup emacs
It’s well worth taking a couple minutes to get syntax highlighting and a slew of other features running in emacs. The simplest thing is to install the extensions that come with OCaml. As root, run:
# sudo make -C emacs install
At Skydeck, we use Tuareg. It comes with instructions for installing. It’s a little more of a manual process and needs to be tailored to your specific setup, so if you’re interested, just follow the instructions in the README that comes with it.
4. Work through the tutorial
Now that you’re ready to write code, the OCaml Tutorial is a great place to start. It will walk you through the language and get you going as quickly as possible.
5. Sign up for the mail lists
Sign up for both the and the ocaml_beginners and the caml-list.
That’s it! You’ll be writing tight code in no time.