Search code examples
ubuntuocamlwindows-subsystem-for-linuxopamocaml-dune

Installing Opam and OCaml on Windows with WSL Ubuntu


I am trying to install OCaml on Windows using WSL. I followed these instructions: Install WSL

So I opened a PowerShell and typed wsl --install

After having rebooted, I started the Windows Command Prompt as administrator and here is my output:

C:\Windows\System32>ubuntu
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: florianingerl
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.153.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage


This message is shown once a day. To disable it please create the
/home/florianingerl/.hushlogin file.
florianingerl@FLORI-LENOVO-93:~$ bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)"
## Downloading opam 2.1.6 for linux on x86_64...
## Downloaded.
## Where should it be installed ? [/usr/local/bin]
Write access to '/usr/local/bin' required, using 'sudo'.
Command: install -m 755 /tmp/opam-2.1.6-x86_64-linux /usr/local/bin/opam
[sudo] password for florianingerl:
## opam 2.1.6 installed to /usr/local/bin
## Run this script again with '--restore ' to revert.
florianingerl@FLORI-LENOVO-93:~$ opam --version
2.1.6
florianingerl@FLORI-LENOVO-93:~$ ocaml --version
Command 'ocaml' not found, but can be installed with:
sudo apt install ocaml-interp
florianingerl@FLORI-LENOVO-93:~$ sudo apt install ocaml-interp
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package ocaml-interp
florianingerl@FLORI-LENOVO-93:~$ opam init -y
No configuration file found, using built-in defaults.
Checking for available remotes: rsync and local, git.
  - you won't be able to use mercurial repositories unless you install the hg command on your system.
  - you won't be able to use darcs repositories unless you install the darcs command on your system.

[WARNING] Recommended dependencies -- most packages rely on these:
  - make
  - cc
[ERROR] Missing dependencies -- the following commands are required for opam to operate:
  - unzip
  - bwrap: Sandboxing tool bwrap was not found. You should install 'bubblewrap'. See
    https://opam.ocaml.org/doc/FAQ.html#Why-does-opam-require-bwrap.

I am completely new to Ubuntu. I just want to install OCaml. So how do I now install the OCaml compiler via Opam or else. What are the commands to install unzip or bwrap, if these need to be installed first. How to install dune after having installed ocaml?


Solution

  • Use opam rather than your OS package manager to install ocaml and dune.

    opam update
    opam switch create 5.2.0
    

    For dune:

    opam install dune