Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Set Up and Use WSL2 on Windows

Windows Subsystem for Linux 2 (WSL2) is a compatibility layer designed to run Linux binary executables natively on Windows 10 and Windows 11. It provides a real Linux kernel and improved performance over its predecessor, WSL1. WSL2 is important for developers and system administrators who need to run Linux tools and workflows on a Windows machine without the overhead of a virtual machine.


With WSL2, you can use Linux distributions such as Ubuntu, Debian, and Fedora directly from your Windows environment. This integration allows for seamless file sharing between Windows and Linux, making it easier to develop cross-platform applications.


Examples:


1. Enable WSL and Install WSL2:
To get started with WSL2, you need to enable the Windows Subsystem for Linux and install the required components.


Open PowerShell as an administrator and run the following commands:


   # Enable the Windows Subsystem for Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

# Enable the Virtual Machine Platform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

# Restart your computer to apply the changes
Restart-Computer

2. Set WSL2 as the Default Version:
After your system restarts, set WSL2 as the default version for new Linux distributions.


   wsl --set-default-version 2

3. Install a Linux Distribution:
You can install a Linux distribution from the Microsoft Store. For example, to install Ubuntu:



  • Open the Microsoft Store.

  • Search for "Ubuntu" and select the desired version.

  • Click "Get" to download and install the distribution.


4. Initialize the Linux Distribution:
Once installed, launch the Linux distribution from the Start menu. The first time you run it, you will need to complete the initial setup by creating a new user account.


5. Running Linux Commands:
You can now run Linux commands directly from the WSL terminal. For example, to update the package list and install a package:


   sudo apt update
sudo apt install git

6. Accessing Windows Files from WSL:
You can access your Windows files from within the WSL environment. Windows drives are mounted under the /mnt directory. For example, to navigate to your C: drive:


   cd /mnt/c

7. Running WSL from CMD or PowerShell:
You can also run WSL commands directly from CMD or PowerShell. For example, to list the contents of the home directory in your Linux distribution:


   wsl ls ~

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.