DEV Community

milktea02
milktea02

Posted on

Upgrading to WSL2 (so I can install Rust)

TL;DR: Follow this guide someone has kindly posted.

Trying to install Rust and failing on WSL1 on Windows 11 led me to needing to upgrade from WSL1 to WSL2.

As you can see in my powershell I'm running version 1 of the wsl:

PS > wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Running         1
Enter fullscreen mode Exit fullscreen mode

First, step is downloading and installing the new kernel package.

Secondly, enabling Virtual Machine feature:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Enter fullscreen mode Exit fullscreen mode

Remember to run powershell as an admin!

Error: 740

Elevated permissions are required to run DISM.
Use an elevated command prompt to complete these tasks.
Enter fullscreen mode Exit fullscreen mode

Success:

Deployment Image Servicing and Management tool
Version: 10.0.22000.1

Image Version: 10.0.22000.556

Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.
Enter fullscreen mode Exit fullscreen mode

You maybe also need to enable in BIOS as well depending on your PC manufacturer. Windows 11 on Lenovo apparently has this enabled by default.

Now time to install the new kernel we downloaded in step 1:
wsl install prompt

It turns out I also needed to restart my computer for the virtualization enablement to take affect:

PS C:\WINDOWS\system32> wsl --set-default-version 2
Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS.
For information please visit https://aka.ms/wsl2-install
Enter fullscreen mode Exit fullscreen mode

Now to set to version 2:

PS C:\WINDOWS\system32> wsl --set-default-version 2
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
The operation completed successfully.
Enter fullscreen mode Exit fullscreen mode

Oddly enough this didn't work - possibly because I needed to specify which linux distribution I would like to use wsl2?

PS C:\WINDOWS\system32> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Stopped         1
PS C:\WINDOWS\system32> wsl --set-version ubuntu 2
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion complete.
PS C:\WINDOWS\system32> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Stopped         2
Enter fullscreen mode Exit fullscreen mode

Can I finally install Rust on Ubuntu on WSL 2?

Something something about running scripts through a cURL request but it's from rust-lang.org and you can always take a look at the script from https://sh.rustup.rs:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Enter fullscreen mode Exit fullscreen mode
Rust is installed now. Great!
Enter fullscreen mode Exit fullscreen mode
$ rustup -V
rustup 1.24.3 (ce5817a94 2021-05-31)
$ rustc --version
rustc 1.60.0 (7737e0b5c 2022-04-04)
$ cargo --version
cargo 1.60.0 (d1fd9fe 2022-03-01)
Enter fullscreen mode Exit fullscreen mode

ayy!

Top comments (0)