229

I have Windows Subsystem for Linux, but I don't know which version I have, and many things won't work in version 1. How do I check my version?

K7AAY
  • 17,705

6 Answers6

193
  1. At a Windows 10 command prompt, run ver. Is the next-to-last numeric group version 18917 or higher? If so, it is possible you have WSL 2 but not yet verified. Go on to step A or B.
    If you do not see Windows version 18917 or higher, you have version 1.
    This illustrates the result when the OS is Build 16299:

    Version 16299

    A. Open Windows PowerShell or cmd and enter the command wsl -l -v. If version 2 is installed properly, you will see the version number. If you don't see a version number, or if you see an error message (Thank you, Cornea Valentin) you have version 1 (you may also see a version number '1' which could indicate that you're running v1 - see here). Uninstall it then reinstall it as per https://scotch.io/bar-talk/trying-the-new-wsl-2-its-fast-windows-subsystem-for-linux

    B. From the WSL shell prompt, run uname or uname -r. If the kernel version >= 4.19, it's WSL Version 2.

Why is this relevant?

WSL 1 was based on Microsoft's Linux-compatible kernel interface, a compatibility translation layer with no Linux kernel code.

WSL 2 was redesigned with a Linux kernel running in a lightweight VM environment, and innovators have found many more things they can do with WSL 2.

Windows 10 Version 2004 (build 19041.153 & later) enhances WSL2 further; see https://devblogs.microsoft.com/commandline/wsl2-will-be-generally-available-in-windows-10-version-2004/ and https://winaero.com/blog/wsl2-will-ship-with-windows-10-version-2004-with-kernel-updates-via-windows-update/ .

K7AAY
  • 17,705
115
  1. Open PowerShell
  2. Check the version with wsl -l -v
  3. If at version 1, then update the version with wsl --set-version Ubuntu-20.04 2

Note: Changing the version of a running OS will terminate it. The name of the OS need not be Ubuntu-20.04 for you. Please select the actual name listed in wsl -l -v

If you are not able to update to version 2, then you may not be on the WSL 2 Kernel. This can be downloaded from Microsoft.

Jack
  • 4,029
11

In the WSL version I was running, I just typed uname -r to which I got the result

5.4.72-microsoft-standard-WSL2

So, I can say that its WSL2, so you can try running uname -r and check.

Luce
  • 305
4

Programmatically:

# Multiline 
wsl.exe -l -v |
iconv -f utf16 |
egrep "\b${WSL_DISTRO_NAME}\s+Running" |
tr -d '\r' |
sed 's/.*\([[:digit:]]\)[[:space:]]*/\1/'

Will return 1 or 2.

Line-by-line, this:

  • Executes wsl.exe -l -v to return the full list of all distributions you might have installed

  • Runs it through iconv to fix its malformed UTF16 output. You don't normally see the problem unless you try to grep it (or pipe it to something like hexdump -C), but you have to clean it up before you can grep it.

  • Matches the current instance (via $WSL_DISTRO_NAME) line

  • Removes the DOS line ending

  • Finds the version number in the line and outputs it

Thanks to this Super User answer for the concept.

This will work as long as Interop is enabled for WSL.

If Interop isn't enabled, then a fallback method is to check /proc/cmdline:

  • /proc/cmdline on WSL1 is BOOT_IMAGE=/kernel init=/init
  • /proc/cmdline on WSL2 is initrd=\initrd.img panic=-1 pty.legacy_count=0 nr_cpus=16

So:

  • grep -q "^BOOT_IMAGE" /proc/cmdline returns success on WSL1 but error on WSL2
  • grep -q "^initrd" /proc/cmdline returns success on WSL2 but error on WSL1

This currently works (and has for the last year, at least), but could change in the future if either the WSL1 or WSL2 architecture changes in some way. However, I expect that the /proc/cmdline is likely always going to differ between WSL1 and WSL2 and can be programmatically parsed to determine the current version.

NotTheDr01ds
  • 22,082
2

In the Windows Command Prompt, run wsl --version

If it prints the WSL version info, then you have WSL2.

If it prints the help text, then you have WSL1.

wisbucky
  • 2,762
  • 32
  • 17
-2

If you happen to be running Docker for Windows and you have WSL 1, then if you enter docker in the terminal for your WSL, you'll see the message The command 'docker' could not be found in this WSL 1 distro., which is a very clear confirmation.