Using WSL on Windows 11
October 28, 2024 · AI Conversations
### 1. **Install a Linux Distribution**
– Open the **Microsoft Store**, search for a Linux distribution (like Ubuntu, Debian, or Kali Linux), and click **Install**.
– After installing, launch the distribution from the Start Menu to complete the setup. This will prompt you to create a new user and password for Linux.
### 2. **Launch WSL**
– You can launch WSL by opening a terminal. Type `wsl` in the **Windows Terminal**, **Command Prompt**, or **PowerShell**. This will open your default WSL distribution.
– To launch a specific distribution, type:
wsl -d <distribution_name>
For example, `wsl -d Ubuntu`.
### 3. **Use WSL Commands**
– **List Installed Distributions:** Use `wsl -l -v` to list installed distributions and check their WSL version.
– **Switch WSL Versions:** To set a distribution to WSL 2, use:
wsl --set-version <distribution_name> 2
– **Set Default Distribution:** Use `wsl –set-default ` to set a default.
### 4. **Accessing Files Across Windows and WSL**
– You can access Windows files from WSL at `/mnt/c` (and other drives as `/mnt/d`, `/mnt/e`, etc.).
– To access WSL files from Windows, go to `\wsl$` in File Explorer.
### 5. **Install and Use Development Tools**
– Now you can install Linux-based tools using your distribution's package manager (e.g., `sudo apt install ` in Ubuntu).
### 6. **Running WSL Commands in Windows**
– You can run Linux commands directly in PowerShell or Command Prompt using:
wsl <command>
– Example:
wsl ls /home
After setup, you’ll be able to seamlessly run Linux commands, scripts, and applications alongside your Windows tools.
### 1. **Using Windows Terminal, PowerShell, or Command Prompt**
– Open **Windows Terminal**, **PowerShell**, or **Command Prompt**.
– Simply type:
wsl
This will open your default Linux distribution in WSL.
### 2. **Starting a Specific Distribution**
– To start a specific distribution, use the `-d` flag:
wsl -d <distribution_name>
Replace “ with the name of your Linux distribution, like `Ubuntu`.
### 3. **Using the Start Menu**
– Go to the **Start Menu**, find your Linux distribution (e.g., "Ubuntu" or "Debian"), and click on it.
– This will launch your distribution in a new terminal window.
### 4. **Using Windows File Explorer**
– Open **File Explorer** and enter the path `\wsl$` in the address bar.
– This will show a list of your installed WSL distributions. Opening a distribution will start WSL if it’s not already running.
Once started, you’ll be in your Linux environment and can run commands as you would on a regular Linux terminal.
### 1. **Enable WSL 2 and Virtual Machine Platform**
– Open **PowerShell** as Administrator and run the following commands to enable WSL and the Virtual Machine Platform:
wsl --install
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
– Restart your computer after enabling these features.
### 2. **Install Docker Desktop for Windows**
– Download **Docker Desktop** for Windows from [Docker’s official website](https://www.docker.com/products/docker-desktop).
– Run the installer and follow the setup steps. During installation, make sure to select the option to **Use WSL 2 instead of Hyper-V** (if prompted).
### 3. **Configure Docker to Use WSL 2**
– After installation, open **Docker Desktop**.
– Go to **Settings** (gear icon) > **General** and ensure that **Use the WSL 2 based engine** is checked.
– In **Settings > Resources > WSL Integration**, enable integration with your installed Linux distributions (e.g., Ubuntu).
– Click **Apply & Restart** if prompted.
### 4. **Verify Docker Installation**
– Open a WSL terminal (e.g., Ubuntu) and run the following command to check if Docker is working:
docker --version
– You can also try running a test container:
docker run hello-world
This should download the `hello-world` image and display a welcome message if Docker is working correctly.
### 5. **Use Docker Commands in WSL**
– Now, you can use Docker commands directly from your WSL terminal.
### 6. **Optional: Install Docker Compose**
– Docker Desktop includes Docker Compose, so you should already have it. Run this command to confirm:
docker-compose --version
Docker is now set up on Windows 11 with WSL and ready for use!