How do I run Linux commands on Windows 11?

Published on Aug. 22, 2023, 12:12 p.m.

Windows Subsystem for Linux (WSL) is a compatibility layer that allows you to run your favorite flavor of Linux distributions.You can run Linux on top of Windows 11 (or without the need for a dual boot).

Unlike Windows 10, Windows 11 comes with WSL 2.0, an upgraded version of WSL.In addition to that, WSL 2 on Windows 11 now supports graphical user interfaces and audio natively .

Prerequisites to Install Linux on Windows 11

Before you install Linux on Windows 11, you need to check the firmware.

To do that, open Windows 11 Task manager (Ctrl + Shift + Esc) then ensure ‘Virtualization’ is ‘Enabled’ at the bottom of the right side page.

Install Linux Distribution on Windows 11

Here’s how you can enable WSL.

Install Windows Subsystem for Linux using Windows Features

With Windows Subsystem for Linux installed, you would be able to run Linux applications.

If your PC comes pre-loaded with Windows 11, you might have WSL already enabled.

First, open the start menu and search for ‘Windows features’.Then, select the ‘Turn Windows features on and off’ control panel option .

In the Windows Features dialog box, tick the ‘Windows Subsystem for Linux’ option and then ‘OK’ .

Once the changes are applied, click ‘Restart now’ .

If you want to only install WSL 1, you can now restart your computer.

We recommend you upgrade your WSL to version 2 for faster performance speed.To do that, you need to enable the ‘Virtual Machine Platform’ feature on the Windows features control panel.

Set WSL 2 as the Default Version.

Before setting up WSL 2 as your default version for all Linux distributions from this link.

It will take seconds.

To set WSL 2 as your default version when installing a new Linux distribution.

wsl –set-default-version 2

Then restart your system to switch WSL 1 to WSL 2.

Install WSL from Microsoft Store

You can also download WSL from the Microsoft Store.Start up the Microsoft Store app and search for ‘Windows Subsystem for Linux’.

In the Microsoft Store, you can search ‘Linux’ to get the list of Linux distros available .

For example, here we are searching for ‘ubuntu’.Then, choose the Ubuntu version that you want to install from the list.

On the Ubuntu distribution page,click the ‘Get’ button.

It will automatically be installed on your device once downloaded.

After installation,click the ‘Open’ button to open the Linux terminal.You can launch the app from the Windows start menu.

Install WSL and Linux using Windows Terminal (Cmd or PowerShell) in Windows 11

This is the easiest way to install Linux.You can install Ubuntu with a single command.

First open Windows Terminal by right-clicking the start menu and selecting ‘Terminal (Admin).

When the Windows Terminal opens, type the following command and press Enter to install WSL:

wsl --install

This will get a list of Linux distributions.

To install a new distro, use the following command :

wsl --install -d <Distro>

This command installs Ubuntu as the default Linux distribution.

When the installation is complete, you should see this message.After you see this message, restart your device.

Then, enter the new username and password.

Once the Ubuntu or other Linux distribution is installed, you would be able to access the Linux terminal.Open the Start menu, search for ‘Ubuntu’.

You can open Windows Terminal and then tap the down arrow button on the Tab Bar.

Now, you can use the Linux Bash Shell in Windows.

Alternatively, you can just type the distro name.

To get more details (such as options, arguments, usage, etc) about a specific command, type help followed by the command name.

For example, we want to update the package named “curl” only.

sudo apt --only-upgrade install curl

To upgrade all available packages:

sudo apt upgrade

To create a new user account using the below command :

sudo adduser <username>

To get the list of user accounts on your Linux console, type the following command .

cat /etc/passwd|more

Set Default User for WSL Linux Distro

If you want to set another user account as the default UNIX user for WSL.

debian config --default-user <new_user_name>

To switch users in the WSL Linux distro.

su - <username>

To remove a specific user account from the WSL Linux distro:

sudo deluser <username>

In case your password is compromised you can use the following command:

sudo passwd root

However, if you have multiple Linux distributions on your computer, you can start a specific Linux distro:

wsl -d <DistributionName>

If you wish to log in to a WSL distro with a specific user, type the below command:

wsl --distribution debian --user rajstd

If your computer has multiple Linux Distro running in the background:

wsl --shutdown

To remove or uninstall a Linux distro from WSL.

wsl --unregister <DistributionName>

Once you run the above command, it will remove all the data, settings.

Use the below syntax command to mount that disk.

wsl --mount <DiskPath>

The above command mounts the given disk globally so that it is available to all.

It will automatically assume it is an EXT4 file system.However, if your disk has a different file system, you will need to specify it.

wsl --mount \\.\PHYSICALDRIVE2 --bare --type ext3
wsl --unmount <DiskPath>

You can also edit your Windows files (e.g., text files .

sudo nano /mnt/f/Projects/TestREF.txt

Then, use the rm command to remove the unwanted files:

rm final_report.docx

Install Linux GUI apps

To install apps in WSL.

sudo apt-get install APP-NAME -y
sudo apt install gedit -y
apt install firefox -y

To list all the packages that you have installed using on your distro.

apt list --installed

You’ll become a pro in using Linux on your Windows 11 PC in no time.