Haskell toolchain on Windows/WSL2

Below are outlined two routes to setting up a Haskell toolchain on Windows: the native route and the Windows Subsystem for Linux (WSL) route. I'm grateful to Dustin Thomas and My Dinh for providing the writeups.

Native install

We will install GHCup in our working Windows environment.

  1. Open Windows Powershell by right-clicking the Windows icon on the taskbar and choosing "Windows Powershell". Or you can simply push the "Windows" key on the keyboard and type "Windows Powershell" to search for it. After that, run the following command in Powershell:

    Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; try { Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $true } catch { Write-Error $_ }

    Or you can get the command from here: https://www.haskell.org/ghcup/, if you don't trust me and my random command.

  2. Press "Enter" to confirm the location for GHCup (it will be installed in C:\ghcup)

  3. Press "Enter" again to confirm the location for Cabal (it will be installed in C:\cabal)

  4. Enter "Y" and press "Enter" to install the Haskell language server

  5. Enter "Y" and press "Enter" to install Stack

  6. Enter "Y" and press "Enter" to install MSys2

This might take a while to install so you can read through the machine problem while waiting for everything to set up. After it's done with GHCup and Cabal installation, it will open a MinGW window to install additional packages. If it prompts "Enter any key to exit", it means you're done. Congratulations!

Now you can use Stack, GHCi, GHCup in Command Line or Powershell. For development, open VSCode without WSL remote connection and install Haskell extension.

If you have any problems, shoot me a message on Discord to Dolfenal#6615 or send an email to mdinh AT hawk DOT iit DOT edu. I'm not an expert but I will try my best to troubleshoot it with you.

WSL-based install

In the Windows Store, search "wsl". The Windows Subsystem for Linux should be the first option, install that. Also select a Linux distro from the list of apps, for anyone unfamiliar I would recommend Ubuntu. After installation is complete, reboot your computer.

Installing WSL

Alternatively, you can open a terminal and run "wsl --install" to do the same thing. After installation is complete, you will still need to reboot.

Switching WSL versions

There are two versions of WSL, you should be using version 2. You can check which version you're using by running "wsl --list -v" in a terminal, which will return a list like this:

Switching WSL versions

If the version number is 1, you can change it using "wsl -- set-version [distro name] 2", replacing distro name with the name that appears in your list.

Starting WSL

There may be an icon for the distribution you're using on the start menu. Additionally, if you have Windows Terminal installed, there should be a profile created there for your distribution of Ubuntu. Otherwise, open a terminal and run the command "wsl", which will automatically launch your installed distro of Linux. On firstrun, you will need to setup your user account, which the command line will guide you through.

If you're using Ubuntu, make sure to run "sudo apt update" and "sudo apt upgrade" to update the software on your system.

Installing GHCup

Install the required dependencies for GHCup:

sudo apt install build-essential curl libffi-dev libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5

Follow the Linux instructions for installing GHCup. In the Linux terminal run:

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

if it asks you about adding GHCup to the $PATH variable, go ahead and add it; prepend or append doesn't matter, but it will make accessing GHCup easier.

After installing, restart your terminal.

Using WSL in VSCode

Before doing this, make sure you launch your Linux distro at least once. In VSCode, install the WSL extension. Once you do that, click the remote icon on the bottom left of VSCode:

Remote icon

Then select "New WSL Window" on the command palette:

New WSL Window

This will open a new window that is connected to the distro you installed. In your WSL environment VSCode instance, you will need to download the Haskell extension for code formatting.

I have noticed these issues pop up on the lectures repo, unsure of how to fix it but will update once I figure it out:

Known issues

Accessing Windows files in Linux

in the Linux filesystem, your Windows filesystem is mounted at /mnt/c. to access your Windows user folder use "cd /mnt/c/Users/[your user folder name]" adding in your user folder name. This can be found by running "ls /mnt/c/Users"

Accessing Linux files in Windows

You can find your Linux files in the left side of the File Explorer, underneath the "Network" group.

File explorer

You can find your user folder under "Linux/[your distro]/home/[your username]", replacing distro and username accordingly.

Addendum on getting graphics working

To install the graphics package used in the first machine problem (gloss), you may need to do:

sudo apt update
sudo apt install libglu1-mesa-dev freeglut3-dev mesa-common-dev mesa-utils

before doing stack build

Should take some time to build but that should cover the missing dependencies.

Troubleshooting issues

On first run I had an issue where the yellow circle would not render. After installing Intel's drivers for WSL it seemed to fix the issue, please let me know if you run into similar issues on a different system.

To determine where OpenGL is rendering:

glxinfo | grep 'OpenGL renderer string'

Nvidia supposedly does not support OpenGL within WSL, but Intel does. If you have a system with an Intel CPU and the renderer string says something like this:

OpenGL renderer string: D3D12 (Intel(R) Iris(R) Xe Graphics)

you should be fine. Your mileage may vary depending on your system configuration, but the best advice I can give is making sure your graphics drivers are up to date.

Otherwise, install drivers as specified in this article: https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps


I can answer any further WSL setup questions via email (dthomas18 AT hawk DOT iit DOT edu). I am also in the cs@iit discord, my username is @Captain Lobster#4008; I check there regularly and can answer any questions there. I hope my instructions are helpful.