How to locate all the switches in Visual Studio Code

I installed WLS2, and then Ubuntu on Windows 11, and finally OCaml. Here are the switches that I have:


However, Visual Studio Code is unable to locate those:

Would you kindly help me in locating the folder with those switches on my machine?

WSL2 can be a bit tricky since executables can run in native Windows or inside WSL2 … and it gives you no indication which one.

So first, can you check that a WSL2 opam is running? Just dump the output from the following:

command -v opam
opam var --global
echo $PATH

Assuming that opam really is a WSL2 opam, then you also need to make sure VS Code is switched to WSL2.

So second, at the bottom left of your VS Code is a button that should be blue if VS Code is switched to WSL2. If it isn’t blue click on that and make sure it is WSL2.

Last, use Select Sandbox not Open Folder for your switches. You only use the Open Folder if the opam switch shows an absolute path.

I believe that I am half way there. So, let me start with the outputs of the commands:

pyvovale@DESKTOP-64CEB9F:~$ command -v opam
/usr/bin/opam
pyvovale@DESKTOP-64CEB9F:~$ opam var --global
arch              x86_64               # Inferred from system
exe                                    # Suffix needed for executable filenames (Windows)
jobs              7                    # The number of parallel jobs set up in opam configuration
make              make                 # The 'make' command to use
opam-version      2.2.0                # The currently running opam version
os                linux                # Inferred from system
os-distribution   ubuntu               # Inferred from system
os-family         debian               # Inferred from system
os-version        22.04                # Inferred from system
root              /home/pyvovale/.opam # The current opam root directory
switch            ocaml_52             # The identifier of the current switch
sys-ocaml-arch    x86_64               # Target architecture of the OCaml compiler present on your system
sys-ocaml-cc      cc                   # Host C Compiler type of the OCaml compiler present on your system
sys-ocaml-libc    libc                 # Host C Runtime Library type of the OCaml compiler present on your system
sys-ocaml-system  linux                # Target system of the OCaml compiler present on your system
sys-ocaml-version 4.13.1               # OCaml version present on your system independently of opam, if any
pyvovale@DESKTOP-64CEB9F:~$ echo $PATH
/home/pyvovale/.opam/ocaml_52/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/Common Files/Oracle/Java/javapath:/mnt/c/Program Files/Microsoft/jdk-11.0.23.9-hotspot/bin:/mnt/c/windows/system32:/mnt/c/windows:/mnt/c/windows/System32/Wbem:/mnt/c/windows/System32/WindowsPowerShell/v1.0/:/mnt/c/windows/System32/OpenSSH/:/mnt/c/Program Files/Microsoft SQL Server/150/Tools/Binn/:/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/:/mnt/c/Program Files/dotnet/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/HP/HP One Agent:/mnt/c/Program Files (x86)/sbt/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/PowerShell/7/:/mnt/c/Users/shuri/AppData/Local/Programs/opam/bin:/mnt/c/Users/shuri/.elan/bin:/mnt/c/Users/shuri/.cargo/bin:/mnt/c/Users/shuri/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/shuri/AppData/Local/Programs/MiKTeX/miktex/bin/x64/:/mnt/c/Users/shuri/.dotnet/tools:/mnt/c/Users/shuri/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/ghcup/bin:/mnt/c/Users/shuri/AppData/Local/Coursier/data/bin:/mnt/c/Users/shuri/.dotnet/tools:/mnt/c/Users/shuri/.dotnet/tools:/mnt/c/MinGW/bin:/mnt/c/Users/shuri/.dotnet/tools:/snap/bin

In Visual Studio Code, I clicked to the bottom left corner on ‘Connect to WSL’, then I installed OCaml Platform on Ubuntu, and then all the switches became visible. However, I could not figure out how may I navigate to the folder on my C drive where some of the .ml files are located. Moreover, when I click on some of the recently opened folders I am getting immediately disconnected from from the WSL server. Would you kindly provide me with some further assistance?

Just like on Windows where you can mount a network path to a drive letter (ex. Z:), in WSL2 it mounts Windows drives to a Unix path.

On your machine the C: drive was mapped to /mnt/c in WSL2.
So C:\dev\OCaml\RealWorldOCaml is at /mnt/c/dev/OCaml/RealWorldOCaml.

But a word of caution: These mounts can be 100X slower than a normal disk drive. When people complain about the speed of WSL2, the mount is almost always the culprit. Microsoft explains the details at Working across file systems | Microsoft Learn. TLDR: Move your files to /home/pyvovale/dev/OCaml/RealWorldOCaml (which is on a Linux ext4 filesystem) and then open that folder in VS Code.

(For future people who are just starting WSL2, you’ll need to learn how to move/copy/explore/change directories from the Linux command line. Try Linux Commands in more detail | High Performance Computing).

1 Like

Thank you so much! Moved everything to home directory

Actually Visual Studio Code gives a warning when trying to access a path with mnt

Would you mind answering a linux question which not related to OCaml? Here it is:
This section intrigued me quite a bit. I am getting an error that wsl.localhost is not accessible when trying to view linux folder with the explorer. A solution is presented here, but I did not understand it. Do you have some time to explain it to me

I can access \\wsl$ from the File Explorer, although \\wsl.localhost$ does not work.

Other than that, I don’t have a clue.

Here is a solution, to the issue with \wsl$