Upgrading to WSL2 (so I can install Rust)
Tags: wsl, wsl2, rust
Published: 2022-05-09 03:58:28

---
title: Upgrading to WSL2 (so I can install Rust)
published: true
description: 
tags: wsl, wsl2, rust
//cover_image: https://direct_url_to_image.jpg
---

TL;DR: Follow this [guide](https://github.com/rust-lang/rustup/issues/2887#issuecomment-1093620664) someone has kindly posted.

Trying to install [Rust](https://www.rust-lang.org/tools/install) and [failing](https://github.com/rust-lang/rustup/issues/2887) on WSL1 on Windows 11 led me to needing to [upgrade from WSL1 to WSL2](https://docs.microsoft.com/en-us/windows/wsl/install#upgrade-version-from-wsl-1-to-wsl-2).

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

```powershell
PS > wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Running         1
```

First, step is [downloading and installing the new kernel package](https://docs.microsoft.com/en-us/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package).

Secondly, [enabling Virtual Machine feature](https://docs.microsoft.com/en-us/windows/wsl/install-manual#step-3---enable-virtual-machine-feature):

```powershell
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
```

Remember to run powershell as an admin!

```powershell
Error: 740

Elevated permissions are required to run DISM.
Use an elevated command prompt to complete these tasks.
```

Success:

```powershell
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.
```
You  maybe also need to [enable in BIOS](https://support.microsoft.com/en-us/windows/enable-virtualization-on-windows-11-pcs-c5578302-6e43-4b4b-a449-8ced115f58e1) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jftmkwwwup41n8p8i5ge.png)

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

```powershell
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
```

Now to set to version 2:

```powershell
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.
```

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

```powershell
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
```

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`:

```sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

```sh
Rust is installed now. Great!
```

```sh
$ 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)
```

ayy!