Ova

How to install Kali WSL from command line?

Published in WSL Kali Installation 4 mins read

How to Set Up WSL and Install Kali Linux for WSL, Primarily Using the Command Line

Installing Kali Linux on Windows Subsystem for Linux (WSL) involves several command-line steps to enable the necessary features, followed by the installation of the Kali distribution itself.

Prerequisites

Before you begin, ensure your system meets the following requirements:

  • Windows Version: Windows 10 (version 1903 or higher, Build 18362 or higher) or Windows 11.
  • Internet Connection: An active internet connection to download necessary components.
  • Administrator Privileges: You will need to open a command prompt or PowerShell with administrator rights for initial setup steps.

Step 1: Enable WSL and Virtual Machine Platform Features

The first step is to enable the core Windows Subsystem for Linux features and the Virtual Machine Platform, which is essential for running WSL 2.

  1. Open an administrator command prompt (or PowerShell). You can do this by searching for "cmd" or "PowerShell" in the Start Menu, right-clicking the application, and selecting "Run as administrator."

  2. Execute the following commands one by one to enable the required Windows features:

    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    • Explanation: These commands use the Deployment Image Servicing and Management (DISM) tool to activate the "Windows Subsystem for Linux" and "Virtual Machine Platform" features. The /norestart flag prevents an immediate reboot after each command.

Step 2: Restart Your Computer

After enabling the necessary Windows features, a system restart is required for the changes to take full effect.

  • You will be prompted to restart your computer. Proceed with the restart when requested.

Step 3: Install the WSL 2 Linux Kernel Update Package

WSL 2 operates on a dedicated Linux kernel that needs to be manually installed or updated.

  1. After your computer has restarted, download the latest WSL 2 Linux kernel update package from the official Microsoft source:
  2. Locate the downloaded .msi file (e.g., wsl_update_x64.msi) and run it. Follow the on-screen instructions to complete the kernel installation.
    • Note: While this step involves a graphical installer, it is a crucial component for WSL 2 functionality.

Step 4: Restart Your Computer (Again)

Another restart might be necessary after installing the kernel update, particularly if prompted by the installer or your system.

  • Restart your computer if the kernel installer or the system advises you to do so.

Step 5: Set WSL 2 as Your Default Version

Once the kernel update is applied, you should set WSL 2 as the default architecture for any new Linux distributions you install.

  1. Open a standard command prompt (administrator privileges are not strictly necessary for this command, but it won't hurt if you use an admin prompt).

  2. Execute the following command:

    wsl --set-default-version 2
    • Explanation: This command configures WSL to use version 2, which offers improved performance and full system call compatibility, for all future Linux distributions you add. If you encounter an error about a missing kernel, double-check that Step 3 was completed successfully.

Step 6: Install Kali Linux

With your WSL 2 environment prepared, you can now proceed to install the Kali Linux distribution. While the final download and installation are handled by the Microsoft Store, you can initiate this process directly from the command line.

  1. From your command prompt, use the following command to launch the Microsoft Store and navigate directly to the Kali Linux product page:

    start ms-windows-store://pdp/?ProductId=9PKR34TNCV07
    • Explanation: This command utilizes a URI scheme to open the Microsoft Store app and land on the specific page for Kali Linux, streamlining the installation process.
  2. On the Kali Linux page in the Microsoft Store, click the "Get" or "Install" button to begin the download and installation.

  3. Once Kali Linux is installed, you can launch it either from the Windows Start Menu or by simply typing kali in your command prompt and pressing Enter.

  4. The first time you launch Kali Linux, you will be prompted to create a new UNIX username and password, which will be specific to your Kali distribution.

Summary of Command-Line Steps

Here's a concise overview of the primary commands used during this installation process:

Step Action Command Admin Rights Required
1 Enable WSL & Virtual Machine Platform dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Yes
5 Set WSL 2 as Default wsl --set-default-version 2 No
6 Open Kali Store Page start ms-windows-store://pdp/?ProductId=9PKR34TNCV07 No

Further Resources:

By following these command-line driven steps, along with the necessary graphical kernel installation and Microsoft Store acquisition for the distribution, you can successfully set up Kali Linux within your Windows Subsystem for Linux environment.