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). First, install WSL2, which is a virtual machine host. Then, install Ubuntu in WSL2. Then, install OPAM inside Ubuntu.
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 winver, and press Enter. A dialog box will open. It should say, "Version 2004" (or higher) Look on the second line for “OS Build XXXXX.YYY”. If the XXXXX part of that is a number smaller than 19041, you must update Windows now: go to Settings -> Update & Security -> Windows Update -> Check for updates and install updates. When finished, run winver again to double check that the Version is 2004 (or greater) and the build is 19041 (or greater).
- If you can’t get a recent build—perhaps because your hardware is a bit older—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.
- You may be asked to enable Hardware Virtualization, which is a BIOS setting. You'll have to reboot, and click F1 during startup to enter the BIOS, to change this setting.
At the prompt (which is probably something like PS C:\windows\system32), enter the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 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. Ubuntu 20 also works.) 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.
Now you have a Linux (Ubuntu) machineFirst, make sure you have the dependencies that OPAM needs installed:
sudo apt install make m4 gcc unzipA few people seem to have run into problems with install commands for ocaml utilities when they did not have emacs installed. Hence, even if you don't want to use emacs and would prefer to use another editor like VS Code, you probably want to install emacs now like this:
sudo apt install emacsThen, to install OCaml, follow the instructions for the Linux installation.
- 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 326 work. Go ahead and do that with the Windows File Explorer wherever you like. For example, you might create a new folder in your Documents called 326.
Now from the WSL Bash shell, run this command to make your 326 folder easily accessible from WSL:
ln -s /mnt/c/Users/
with whatever your Windows user name is. If you’re not sure, go to the Windows Start Menu and type cmd. A Windows shell will open, and the prompt should be C:\Users\ . If you chose a different folder name in the previous step, then replace Documents/326 with whatever you chose. Your 326 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.
Optional: X Windows
The normal way that Linux opens up new windows is by running an "XWin" server. You can set this up too, so that your Linux DISPLAY variable is set, in a way that enables Linux applications (especially Emacs) to open new windows on your Microsoft Windows display. This article explains how. Scroll down to "Run GUI applications in WSL with X11 Forwarding".