Download ocaml

Download ocaml DEFAULT


The latest page points to the most recent release of the OCaml compiler distribution. Below is a list of the recent releases.

See also the install page for instructions on installing OCaml by other means, such as the OPAM package manager and platform specific package managers.

  • OCaml 4.13.1, Download, released Oct 1, 2021.
  • OCaml 4.13.0, Download, released Sep 24, 2021.
  • OCaml 4.12.1, Download, released Sep 24, 2021.
  • OCaml 4.12.0, Download, released Feb 24, 2021.
  • OCaml 4.11.2, Download, released Feb 24, 2021.
  • OCaml 4.11.1, Download, released Aug 31, 2020.
  • OCaml 4.11.0, Download, released Aug 19, 2020.
  • OCaml 4.10.2, Download, released Dec 8, 2020.
  • OCaml 4.10.1, Download, released Aug 20, 2020.
  • OCaml 4.10.0, Download, released Feb 21, 2020.
  • OCaml 4.09.1, Download, released Mar 18, 2020.
  • OCaml 4.09.0, Download, released Sep 18, 2019.
  • OCaml 4.08.1, Download, released Aug 5, 2019.
  • OCaml 4.08.0, Download, released Jun 14, 2019.
  • OCaml 4.07.1, Download, released Oct 4, 2018.
  • OCaml 4.07.0, Download, released Jul 10, 2018.
  • OCaml 4.06.1, Download, released Feb 16, 2018.
  • OCaml 4.06.0, Download, released Nov 3, 2017.
  • OCaml 4.05.0, Download, released July 13, 2017.
  • OCaml 4.04.2, Download, released Jun 23, 2017.
  • OCaml 4.04.1, Download, released Apr 14, 2017.
  • OCaml 4.04.0, Download, released Nov 4, 2016.
  • OCaml 4.03.0, Download, released Apr 25, 2016.
  • OCaml 4.02.3, Download, released Jul 27, 2015.
  • OCaml 4.02.2, Download, released Jun 17, 2015.
  • OCaml 4.02.1, Download, released Oct 14, 2014.
  • OCaml 4.02.0, Download, released Aug 29, 2014.
    (4.02.0 suffers from one known bug that noticeably increases compilation time, you should use 4.02.1 or later versions instead.)
  • OCaml 4.01.0, Download, released Sep 12, 2013.
  • OCaml 4.00.1, Download, released Oct 5, 2012.
  • OCaml 3.12.1, Download, released July 4, 2011.
  • Earlier releases are available here.

You may also want to check the development version of OCaml.


Installing OCaml for 3110

OCaml logo

These installation instructions assume a basic working knowledge of the “command line” or “terminal”, which is used (e.g.) in CS 1110. If you need to brush up on the command line, it would be a good idea to google for a tutorial.

You need to have a Unix development environment with a working installation of OPAM, the OCaml Package Manager, version 2.x. You have a choice: you can install these on your own operating system, or you can download a Linux virtual machine (VM) that we provide.

  • For Linux or Mac OS X, we suggest trying a native installation first. If that doesn’t work out, install the VM instead.

  • For Windows, we suggest trying a semi-native installation first. This is a new and experimental possibility; we haven’t been able to support it before in 3110. It’s made possible this semester by some advances that Microsoft has recently made with integration of Linux and Windows. We hope it works out, but please bear in mind that it’s new to the course staff, so we might not have all the answers right away. If it doesn’t work out, you can still use the VM, which is what we’ve recommended in the past for Windows.

Regardless of what you choose, once you get an installation working keep it working throughout the semester by being cautious about any updates you apply to your system. Don’t perform any major OS upgrades just before an assignment is due, for example.

Click on the installation method below that you want to use. If you get stuck, please follow the instructions under “Need help?”.

VM installation

WARNING: Do not use a VM from an old edition of CS 3110. Only the Spring 2020 VM will be supported this semester.

With Virtual Machines, there are two operating systems involved: the host operating system (OS) and the guest OS. The host is your own native OS (probably Windows). The guest is the OS that runs “inside” the host. We provide a Linux guest OS in the 3110 VM.

  • Download and install VirtualBox for your host OS. Or, if you already had it installed, make sure you update to the latest version of VirtualBox before proceeding.

  • Go to the 3110 virtual machine download page (that hyperlink will become active shortly before the semester starts). Don’t worry about the “We’re sorry, the preview didn’t load” message you see at that link. Click the Download button and save the file wherever you like. It’s about a 4GB file, so the download might take awhile.

  • Import the virtual machine:

    • Run VirtualBox.

    • Select File → Import Appliance

    • Choose the file you just downloaded. Click Next, then Import.

  • Run the virtual machine:

    • Select vm3110-2020sp from the list of machines in VirtualBox.

    • Click Start.

    • If you get an error about “VT-x/AMD-V hardware acceleration”, you most likely need to enter your computer’s BIOS settings and enable virtualization. The details of that will vary depending on the model and manufacturer of your computer. If you get stuck, please see a consultant for help.

  • Login with username and password .

    (In case you’re curious, this is the standard username/password on a VM built with Vagrant, which is what we use to automate our production of the VM. In fact, you can see the scripts we use to build the VM in this GitHub repo. If you’d rather have a user account on the VM with your own username rather than , you are welcome to create a new account. But be aware that OPAM and VS Code won’t be configured for that user. The instructions to do that initialization can be found below under “OPAM configuration” and “VS Code configuration”.)

  • To launch the OCaml toplevel:

    • Start a terminal by choosing the 2nd icon down from the top in the launcher on the left-hand side of the desktop.

    • Run . Enter followed by the Enter key to evaluate the integer 3110. Stop to appreciate how good an integer it is.

    • Enter or Control-D to exit the toplevel.

  • You can use the guest OS’s own interface to safely shutdown or reboot the VM. But more often you will likely use VirtualBox to close the VM by click the VM window’s “X” icon in the host OS. Then you will be presented with three choices:

    • Save the machine state. This choice is what you normally want. It’s like closing the lid on your laptop: it puts it to sleep, and it can quickly wake.

    • Send the shutdown signal. This choice is like shutting down a machine you don’t intend to use for a long time, or before unplugging a desktop machine from the wall. When you start the machine again later, it will have to boot from scratch, which takes longer.

    • Power off the machine.This choice is dangerous. It is the equivalent of pulling the power cord of a desktop machine from the wall while the machine is still running: it causes the operating system to suddenly quit without doing any cleanup. Doing this even just a handful of times could cause the file system to become corrupted, which will cause you to lose your source code and have to reinstall the VM from scratch. You will be very unhappy.

  • Now setup a shared folder between the host and guest OS.

    • With the VM shutdown (i.e., select “send the shutdown signal”), click Settings, then click Shared Folders.

      • Click the little icon on the right that looks like a folder with a plus sign.

      • In the dialog box, select a Folder Path. This is the folder on your host OS that you want to share with the guest OS. Let’s assume you created a new folder named inside your Documents folder, or wherever you like to keep files.

      • The Folder Name in the dialog box will automatically be filled with . This is the name by which the guest OS will know the folder. You can change it if you like.

      • Check Auto-mount and Make Permanent; do not check Read-only. Make the Mount Point . Click OK, then click OK again.

      • Start the VM again.

      • You should now have a subdirectory named in your home directory. It is shared between the host OS and the guest OS. You can use it to easily transfer files between the two.

  • You’re done!

  • If you wish, you can safely delete the file you downloaded to free up some space.

  • You might be able to improve the performance of your VM by increasing the amount of memory or CPUs allocated to it, though it depends on how much your actual machine has available and what else you have running at the same time. With the VM shut down, try going in Virtual Box to Settings → System, and tinkering with the Base Memory slider on the Motherboard tab, and the Processors slider on the Processor tab. Then bring up the VM again and see how it does. You might have to play around to find a sweet spot.

Semi-native installation: Windows

Overview: We’re going to install a Linux environment inside Windows 10. Microsoft calls it the “Windows Subsystem for Linux” (WSL). Then we’ll install inside OPAM inside WSL. Here is an (optional) introduction to what WSL is and why you need it.

  • Don’t skip this first step:in beta testing of these instructions, most problems resulted from having older builds.

    Check your Windows build. To do that, click Start, type , and press Enter. A dialog box will open. Look on the second line for “OS Build XXXXX.YYY”. If the XXXXX part of that is a number smaller than 17643, you must update Windows now: go to “Settings → Update & Security → Windows Update → Check for updates” and install updates. When finished, run again to double check that the build is 17643 or greater.

    If you can’t get a recent build—perhaps because your hardware is a bit older—you’ll need to install the VM. You could try these instructions to install WSL on older builds. But, (i) we don’t know whether they will work, and (ii) you still might have unknown troubles installing OPAM.

  • Open Windows PowerShell as Administrator. To do that, click Start, type PowerShell, right click on “Windows PowerShell” (which should be at the top as the best match), and click “Run as administrator”. Click Yes to allow changes.

  • At the prompt (which is probably something like ), enter the following command:
  • If you are prompted to restart, do so. Otherwise, close PowerShell.

  • Click Start, type Microsoft Store, and open the Microsoft Store app. Click Search, and type Ubuntu. Scroll down to Apps, and choose Ubuntu, which should be the first result. (Make sure to chose “Ubuntu” not “Ubuntu 16.04 LTS”. In theory “Ubuntu 18.04 LTS” would be fine, because that’s what “Ubuntu” ought to install anyway.) From the Ubuntu page, click Get. After the download finishes, click Launch. The install will then finish.

  • You will be prompted to create a UNIX username and password. You can use any username and password you wish. It has no bearing on your Windows username and password (though you are free to re-use those). You will need to remember the password for future use.

  • You will now be inside a terminal at the Bash shell. The prompt will look something like

    You’ll want to make sure copy-and-paste into the terminal is enabled: Click on the icon on the top left of the shell window, click Properties, and make sure “Use Ctrl+Shift+C/V as Copy/Paste” is checked. (If you don’t see that option, your Windows build is too old. Make sure you updated Windows to a new enough build, as described above. Right-click might still work to paste even if you don’t have a new enough build.) Now Ctrl+Shift+C will copy and Ctrl+Shift+V will paste into the terminal. Note that you have to include Shift as part of that keystroke.

  • Enter the following command into the shell:

    You will be prompted for the UNIX password you chose. The command that you are running is updating the APT package manager, which is what helps install software inside WSL. The prefix means to run the command as the administrator, aka “super user”. In other words, do this command as super user, hence, “sudo”.

    Pro-tip: Running commands with is potentially dangerous and should not be done lightly. Do not get into the habit of putting in front of commands.

  • Now run this command to upgrade all the APT software packages; it will take awhile. If you are prompted about configuring libssl, just hit Enter to accept the default choices.
  • Run this command to install some additional packages:
  • WSL has its own filesystem that is distinct from the Windows filesystem. You can edit Windows files from WSL, but you cannot edit WSL files from Windows. So we need to create a Windows directory in which you will store all your 3110 work. Go ahead and do that with the Windows File Explorer wherever you like. For example, you might create a new folder in your called .

  • Now from the WSL Bash shell, run this command to make your 3110 folder easily accessible from WSL:

    Replace with whatever your Windows user name is. If you’re not sure, go to the Windows Start Menu and type . A Windows shell will open, and the prompt should be . If you chose a different folder name in the previous step, then replace with whatever you chose. You 3110 Windows folder will now be accessible from your WSL home directory.

    For more information about the differences between the Windows and WSL filesystems, and how to work with them, see this guide.

  • Install OPAM by running these commands:

    (You might wonder why we’re not installing OPAM through APT. The problem is that APT has OPAM version 1, not version 2. So we have to manually install OPAM instead of using APT to do it automatically.)

  • Continue with the instructions under “OPAM configuration” below.

Native installation: OS X

You need a Unix package manager. There are two popular managers on Mac, MacPorts and Homebrew. The instructions below assume MacPorts. Whatever you do, do not install both. They do not play nicely together.

If you previously installed one of them, make sure it is in working order and fully up-to-date before proceeding. With MacPorts, that means running followed by . If there are any errors, you need to resolve them before proceeding. Often the easiest way to do that is to uninstall the package manager then reinstall it from scratch.

If you’re starting from scratch, here’s what to do:

  • Follow the MacPorts install instructions:

    • First install Xcode, the Xcode command line tools, and accept the Xcode EULA. The instructions for that are given on the MacPorts install page linked above.
    • Before proceeding with the MacPorts install, pause to install XQuartz. Technically this step is optional, but you can save yourself some potential future trouble with OCaml graphics packages by doing it now.
    • Finally, resume following the instructions on the MacPorts install page, and install MacPorts itself.
  • Open a Terminal. Run .

  • Continue with the instructions under “OPAM configuration” below.

Native installation: Linux

  • It’s best to use your distribution’s package manager to install OPAM. The OPAM installation page has detailed instructions for many popular package managers.

  • Continue with the instructions under “OPAM configuration” below.

OPAM configuration

You do not need to follow these instructions if you are using the VM. We have already done them for you.

  • Check your OPAM version by running . That ought to report that you have OPAM version 2, e.g., . If you instead have version 1, e.g., , you have to fix that before proceeding. Follow the instructions under “Need help?” below.

  • If you have ever had OPAM installed before this semester, we highly recommend that you start fresh instead of trying to upgrade an earlier install. To start fresh, all you have to do is delete the directory , or, move it to a different location—e.g., .

  • This step varies depending on whether you are running on Windows, or on OS X or Linux.

    On Windows (WSL), run the following command to initialize OPAM:

    (We have to disable sandboxing because of an open OPAM issue related to WSL. Hopefully that will be fixed in the future.)

    On OS X or Linux, run this command:

  • Enter the following commands to switch OPAM to the OCaml 4.09.0 compiler:

    If you get an error about 4.09.0 not being a known compiler version, try running .

    Now check your compiler version by running . If that reports anything other than , then something has gone wrong; follow the instructions under “Need help?” below. Be aware that OCaml version 4.09 is the only supported version of the OCaml compiler in CS 3110 this semester. All your code must compile under that version.

  • Enter the following commands to install some OPAM packages that will be needed for CS 3110. Make sure to grab the entirety of the first line, which is quite long.
  • Close the terminal you were in. Open a new terminal. Check that you can run OCaml: Run to launch the OCaml toplevel. Enter followed by the Enter key to evaluate the integer 3110. Stop to appreciate how good an integer it is. Then enter or Control-D to exit the toplevel.

  • Double check your OPAM environment by downloading this script and running from the terminal in the directory in which the script is saved. If it reports any errors, follow the instructions under “Need help?” below.

  • Continue with the instructions below to configure the VS Code editor for OCaml.

VS Code configuration

You do not need to follow these instructions if you are using the VM. We have already done them for you.

The Visual Studio Code (VS Code) editor is our current recommendation for the best OCaml experience in a modern editor. After installing OPAM, and after installing VS Code, you’ll need to install some packages inside the editor itself.

  • Download and install VS Code.

  • Open VS Code. If you are on Windows (WSL), make sure to open VS Code by running in a WSL terminal, not by double-clicking the desktop icon in Windows. VS Code should automatically recommend that you now install the “Remote WSL” extension. Do that now.

  • Go to View → Extensions. Search for “OCaml and Reason IDE”. (Note: you do not want the extension simply named “OCaml”; it is obsolete.) Selection the extension, and click Install. If the “Reload Required” button then appears, click it.

    If you are on Windows (WSL), you may see that there is a “OCaml and Reason IDE - for WSL”, but in our testing of these instructions, we found that extension did not work: so, install the non-WSL version.

    Also if you are on Windows (WSL), make sure that you are installing the “OCaml and Reason IDE” extension remotely on WSL, not locally on Windows.

  • We recommend tweaking a few editor settings. Open the user settings JSON file by (i) going to View → Command Palette, (ii) typing “settings json”, and (iii) selecting Open Settings (JSON). Copy and paste these settings into the window:

    Save the file and close the tab.

    Here is a brief explanation of what you just changed: A tab size of 2 spaces is fairly standard in the OCaml community. The ruler at column 80 will help you not go over the maximum column length, and you could even set it to 78 or 72 if you prefer. The setting will cause your code to be run through a tool called each time you save. That tool re-indents your code according to some fairly good standards, thus will help keep your code beautiful. Note that you can run that tool anytime by right-clicking and selecting “Format Document”, and that there is a shortcut key for it too (which you will see next to “Format Document”).

  • Check that the OCaml integration is working. From the command line, type to open the current directory in VS Code. Create a new file named and save it. Try entering . VS Code should then (i) suggest some completions while you are typing, (ii) colorize the syntax as you type, and (iii) indicate a type error with a squiggle under the . Click on the “Problems” pane or hover over the squiggle to see the error. Put double quotes around to fix the error.

    If you are on Windows (WSL) and get an error about , there’s a good chance that you have the file open through Windows, not through WSL. Make sure that you opened VS Code by typing in the WSL shell, not by double-clicking a file in the Windows File Explorer. For other ways of opening files through WSL, read this documentation.

Need help?

The course staff is happy to help you out with any trouble you might have! You can come to office hours or post on Campuswire. Before posting, please read these tips on asking technical questions.

  1. Preschool prep company
  2. Black ops 3 digital xbox
  3. Awst time now
  4. Download ocaml
  5. Shirakumo bnha


There are two ways to setup this opam repository:

Graphical Installer

You can try the graphical installer:

The installer will first create a customized cygwin environment and then set up opam and OCaml inside this environment. The setup should be easy and fast this way. However, the installer won’t allow you to set custom options: proxy configuration, select the initial OCaml version to install, etc. (If possible, the 64-bit version of cygwin is installed. The 32-bit version is no longer recommended)

Manual Installation

  • Download links:
  • Install cygwin and install the following additional packages through cywin’s setup utility: rsync, patch, diffutils, curl, make, unzip, git, m4, perl - and of course mingw64-i686-gcc-core or mingw64-x86_64-gcc-core.

  • If your logon name contains whitespace characters (e.g. ‘Firstname Lastname’) or any other character that would require quoting inside a unix shell or cmd.exe, follow the instructions there. The name of your home directory should only contain alphanumeric ascii letters, no whitespaces (both, the windows version and the posix version ).

  • Download one of the archives listed above. The archives contain native versions of opam, flexdll and aspcud. They are all not linked against cygwin1.dll, so you can use them both with either the 32-bit or 64-bit version of cygwin. Then proceed inside a cygwin shell:

The above commands will download and install precompiled versions of OCaml. You can also compile it from source:

There are also mingw-versions for the obsolete 4.01.0 version of OCaml available.

Next Step

Install and depext-cygwinports, if you want to use libraries like pcre or lablgtk.

Beginner OCAML Tutorial - 1 - Getting Set Up

How can I install OCaml with OPam on windows?

I was able to run OCaml and Opam in Windows 10 using Windows Subsystem for Linux (WSL) without any problem.

Here's a very detail description and instruction OCaml on Windows: The easy way

Note: 2 typos in the article OCaml on Windows: The easy way as of this post, when you come across these two instructions please use the following

  1. (*add an extra i *)
  2. (*remove # from *)

Hope this helps someone!

**The initial link was removed, so here's the content

OCaml on Windows: The easy way

There have been a number of ways to run OCaml on Windows in the past, and there is an extensive list here. However, they all have downsides, whether that involves depending on someone else to update installer binaries, or having to deal with installing and managing Cygwin just to run OCaml.

Fortunately, with the release of Windows Subsystem for Linux (WSL), it’s possible to use the standard Ubuntu OCaml/OPAM easily from within windows, and integrate it with a windows GUI code editor. This guide assumes that you already have WSL set up - if not come back after setting it up by following this guide.

Given how fundamental modules such as Core by Jane Street are to doing any real work with OCaml we’re going to install the OPAM package manager and Core along with just the compiler. The end result is exactly the set up you need to begin the excellent Real World OCaml guide.

Firstly, we need to download and install ocaml and opam we need to add a personal package archive (ppa) to apt-get because the official Ubuntu repos have occasional issues. The code below adds this private repo to apt-get.

Then just use apt-get to install ocaml, opam and m4 (a macro processor also required for the setup to work properly)

The next step is to set up opam. Start with opam init, which will ask you to give it permission to update your .ocamlinit and .profile files. You can simply answer yes to both to put the changes through.

This lets you run the basic REPL loop with the ocaml command. However, a couple of extra bits and pieces are needed to get to the start of the Real World OCaml guide. We install these extras through opam with the command:

Normally we’d now add the environmental variables to run the environment with the command:

Which should add the variables you need as explained here and here. However, when I tried it on WSL it didn’t work, I think as a side effect of the difference between the way windows and linux handles new lines. You can see this for yourself by running the command and then printenv to see all of the environmental variables - none of the variables have been set.

Instead if we use this command:

Then all of the commands are passed to ‘eval’ as a block, and so the whole thing evaluates cleanly, and if you run printenv you should see all of the required environmental variables.

The only thing that remains is to set up OCaml with the custom utop by editing the .ocamlinit file, which will be in your home directory.

Side Note: If you’re new to bash you might be confused that it doesn’t appear if you run ls in your home directory. This is because of the . in front of the filename which hides it by default. If you run you will be able to see it.

Open this file with whatever your favourite text editor is, e.g. , and then add these lines. This is some OCaml code, which will execute on initialisation, i.e. every time you start up the OCaml environment.

Everything is now doing what it’s supposed to do - if you run ocaml you will get utop with the Core module loaded and be ready to start working through the excellent Real World OCaml guide.

However, there is one last wrinkle. Setting environmental variables this way is temporary - if you exit WSL and then restart it with bash and then rerun printenv you will see that you have lost the environmental variables, and the ocaml command will now fail - unable to find the path for topfind because the environmental variables have gone.

To fix this we can add the command to the bottom of your .bashrc file in your home folder, which is run by bash every time you log in. This ensures that it runs automatically, so that you can just login and run ocaml to have a fully functional ocaml environment set up. If you switch compiler through the opam switch command, you will need to either re-run the command or restart the shell with exit and then bash to push the changes to the environment variables and update the version used by OCaml.

You’re now ready to start Real World OCaml - enjoy! This gives you the REPL loop under bash, which is good for learning. However, for more serious programs you need to write an .ml file - the next part (coming soon) covers building using the bash OCaml environment from a GUI code editor in windows, such as Visual Studio Code.


Ocaml download



The most recent version of OCaml is 4.07.0. It was released on 2018-07-10. Further information and download links can be found on the release page.

Source distribution for Windows and Unix systems

(including Linux, MacOS X, and Cygwin)

Binary distributions for Linux (Intel x86)

Binary distribution for MacOS X

We do not distribute MacOS binaries any more. You should install OPAM and use it to install OCaml.

Binary distributions for Microsoft Windows

Documentation and User's manual

Download directory

All the files are also available in this directory, along with their MD5 checksums.

Caml Light

The most recent stable version of Caml Light is 0.75. It was released on 2002-01-26. Further information can be found on the release page.

Source distribution for Unix systems

(including Linux and MacOS X)

Binary distribution for Microsoft Windows

Documentation and User's manual

OCAML Tutorial 2/33: Installing OCAML and OPAM on Ubuntu Linux



These instruction shows a procedure to install native OCaml binaries in Windows. If your operative system is or later you can also install OCaml through Bash on Ubuntu on Windows. In this case, follow the instruction to install OCaml on Ubuntu.

Install OCaml and Opam

Download OCaml official distribution. It contains both OCaml compilers and Opam packet manager. Suppose you have installed the software in . To be sure you've correcly installed OCaml open and type .

If you see the message you need to add to your Path (Environment Variable).

Add OCaml binaries to path

in and then select in tab, then .

Add to the list.

Install Cygwin

Without Cygwin you can't use Opam. In fact, if you try to open Opam typing in it shows a message: .

Download Cygwin and start the installer. Be sure to check the following packages:

  • automake
  • diffutils
  • libreadline
  • make
  • m4
  • mingw64-x86_64-gcc-core
  • mingw64-x86_64-gmp
  • mingw64-x86_64-openssl
  • mingw64-x86_64-pkg-config
  • mingw64-x86_64-sqlite3
  • patch
  • rlwrap
  • unzip
  • wget

Suppose you have installed the software in ( for 64bit version). Open and type (or one of the executable present in ) to check if you can use the Cygwin executables. If the executable won't open, add to your Path (Environment Variable).

Configure Opam

Open and type to configure Opam.

Then install (part of the OCaml compiler) with

Check if is installed typing it in .

The command is used to add 's executables directory to the enviroment path. If after logout you cannot reach anymore, you can manually add it adding to path the following line: .

Installing packages

Packages are installed through Opam with the command where is the name of the package.

Install UTop

Try running the command . If you have no errors, then typing will open the executable.

If you see the message

you have to manually install the single packages. Try again typing:

Both and might not install. See Troubleshoot section.

Installing Core

You can install package with . On Windows 64bit version (and 64bit Cygwin) you will see the following error:

Troubleshoot: cannot create regular file

If package with name fails to install (where xyz is the name of the package, and 10.1 its version) with the following message:

You have to go in this directory:

and delete the file .

Troubleshoot: cannot load shared library

If you try to open some Opam's package (eg: ) and you see this error:

Run again and try to reopen the executable.

Previous Next


You will also be interested:

Up and Running with OCaml

This page will help you install OCaml, the Dune build system, and support for your favourite text editor or IDE. These instructions work on Windows, Unix systems like Linux, and macOS.

Installing OCaml

There are two procedures: one for Unix-like systems, and one for Windows.

For Linux and macOS

We will install OCaml using opam, the OCaml package manager. We will also use opam when we wish to install third-party OCaml libraries.

For macOS

For Linux the preferred way is to use your system's package manager on Linux (e.g or similar). Details of all installation methods.

Then, we install an OCaml compiler:

Now, OCaml is up and running:

For either Linux or macOS as an alternative, a binary distribution of opam is available:

For Windows

OCaml on Windows is still a work in progress. In the meantime, if you only need to run OCaml programs on a Windows machine, then the simplest solution is to use the Windows Subsystem for Linux 2 (WSL2). WSL2 is a feature that allows Linux programs to run directly on Windows. WSL2 is substantially easier and faster to use than WSL1. Microsoft have comprehensive installation steps for setting up WSL2.

On the other hand, if you need Windows binaries then you will have to use the OCaml for Windows installer which comes in 32bit and 64bit versions. This installer gives you opam and OCaml installations all in one go. It is used from within a Cygwin environment, but the executables produced have no dependency on Cygwin at all. For a more comprehensive update on the state of OCaml on Windows, see the OCaml on Windows page.

The OCaml top level

OCaml comes with two compilers: for native code, and for byte code. We shall use one of those in a moment. But first, let's use OCaml's top level (sometimes known as a REPL in other languages):

We typed the phrase and then signalled to OCaml that we had finished by typing followed by the Enter key. OCaml calculated the result, and its type and showed them to us. We exit by running the built-in function with exit code 0:

There are two ways to improve your experience with the OCaml top level: you can install the popular on your system and invoke instead of to get line-editing facilities inside the OCaml top level, or you can install the alternative top level using opam:

We run it by typing instead of . You can read more about utop.

Installing the Dune build system

Dune is a build system for OCaml. It takes care of all the low level details of OCaml compilation. We install it with opam:

A first project

Let's begin the simplest project with Dune and OCaml. We create a new directory and ask to initialise a new project:

Building our program is as simple as typing :

When we change our program, we type again to make a new executable. We can run the executable with (it's called even when we're not using Windows):

Let's look at the contents of our new directory. Dune has added the file, which is our OCaml program. It has also added our file, which tells dune how to build the program, and a subdirectory, which is dune's working space.

The executable is stored inside the subdirectory, so it's easier to run with . To ship the executable, we can just copy it from inside to somewhere else.

Here is the contents of the automatically-generated file. When we want to add components to your project, such as third-party libraries, we edit this file.

Editor support for OCaml

For Visual Studio Code, and other editors support the Language Server Protocol, the OCaml language server can be installed with opam:

Now, we install the OCaml Platform Visual Studio Code extension from the Visual Studio Marketplace.

Upon first loading an OCaml source file, you may be prompted to select the toolchain in use: pick OCaml the version of OCaml you are using, e.g. 4.11.1 from the list. Now, help is available by hovering over symbols in your program:

Visual Studio Code

On Windows using WSL2 you will remotely connect to your WSL2 instance from Visual Studio Code. Microsoft have a useful blog post covering getting WSL2 and Visual Studio Code connected.

On Windows, we must launch Visual Studio Code from within the Cygwin window, rather than by clicking on its icon (otherwise, the language server will not be found):

For Vim and Emacs, install the Merlin system using opam:

The installation procedure will print instructions on how to link Merlin with your editor.

On Windows, when using Vim, the default cygwin Vim will not work with Merlin. You will need install Vim separately. In addition to the usual instructions printed when installing Merlin, you may need to set the PATH in Vim:


328 329 330 331 332