### WSL Install Commands Examples Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/build-custom-distro.md Examples of `wsl --install` commands demonstrating how to install a default distribution for a flavor or a specific version. ```powershell wsl --install my-distro # Installs 'my-distro-v3' since it's the default for 'my-distro' flavor wsl --install my-distro-v3 # Installs 'my-distro-v3' explicitly wsl --install my-distro-v2 # Installs 'my-distro-v2' explicitly ``` -------------------------------- ### Install software in openSUSE using Zypper Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/linux.md Example command for installing software on openSUSE using its package manager, Zypper. Replace `` with the desired application. ```bash sudo zypper install ``` -------------------------------- ### Open Linux Distribution from Start Menu Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install.md Directly opens a specific installed Linux distribution by typing its name in the Windows Start menu. ```text Ubuntu ``` -------------------------------- ### Install software in Red Hat distributions using yum Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/linux.md Example command for installing software on Red Hat-based distributions using yum. Replace `` with the desired application. ```bash sudo yum install ``` -------------------------------- ### Install software in Arch Linux using pacman Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/linux.md Example command for installing software on Arch Linux using its package manager, pacman. Replace `` with the desired application. ```bash sudo pacman -S ``` -------------------------------- ### Install software in Alpine Linux using apk Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/linux.md Example command for installing software on Alpine Linux using its package manager, apk. Replace `` with the desired application. ```bash sudo apk add ``` -------------------------------- ### Install Spotify using Snap Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/systemd.md Use the snap command-line tool to install applications packaged as snaps. This requires snapd to be installed and running. ```bash snap install spotify ``` -------------------------------- ### Install X11 Apps on WSL Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gui-apps.md Installs a collection of X11 utilities like xclock and xcalc. Use this to get basic graphical Linux tools. ```bash sudo apt install x11-apps -y ``` -------------------------------- ### Start MySQL Service for Security Script Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Ensures the MySQL service is running before executing the security installation script. ```bash sudo service mysql start ``` -------------------------------- ### Example of resize2fs output Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/disk-space.md This is an example of the output you might see after successfully resizing the filesystem. ```text resize2fs 1.44.1 (24-Mar-2021) Filesystem at /dev/sdb is mounted on /; on-line resizing required old_desc_blocks = 32, new_desc_blocks = 38 The filesystem on /dev/sdb is now 78643200 (4k) blocks long. ``` -------------------------------- ### Install software in Ubuntu using apt-get Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/linux.md Use this command to install a new software package in Ubuntu. Replace `` with the desired application. ```bash sudo apt-get install ``` -------------------------------- ### Install Docker Engine in WSL Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gpu-compute.md Install the Docker engine directly in WSL if not using Docker Desktop. Ensure the Docker service is started. ```bash curl https://get.docker.com | sh sudo service docker start ``` -------------------------------- ### Install the Custom Distribution Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/build-custom-distro.md Once your custom distribution is listed, use this command to initiate its installation within WSL. ```powershell wsl.exe --install test-distro-v1 ``` -------------------------------- ### Start Redis Server Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Starts the Redis server service. This command requires superuser privileges. ```bash sudo service redis-server start ``` -------------------------------- ### Example wsl.conf file configuration Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/wsl-config.md This example demonstrates how to configure automount, network, interop, user, and boot settings in the wsl.conf file. It shows how to enable/disable automount, set the mount root, configure network hostname and DNS generation, control interop behavior, specify a default user, and set a command to run on boot. ```bash # Automatically mount Windows drive when the distribution is launched [automount] # Set to true will automount fixed drives (C:/ or D:/) with DrvFs under the root directory set above. Set to false means drives won't be mounted automatically, but need to be mounted manually or with fstab. enabled=true # Sets the directory where fixed drives will be automatically mounted. This example changes the mount location, so your C-drive would be /c, rather than the default /mnt/c. root = / # DrvFs-specific options can be specified. options = "metadata,uid=1003,gid=1003,umask=077,fmask=11,case=off" # Sets the `/etc/fstab` file to be processed when a WSL distribution is launched. mountFsTab=true # Network host settings that enable the DNS server used by WSL 2. This example changes the hostname, sets generateHosts to false, preventing WSL from the default behavior of auto-generating /etc/hosts, and sets generateResolvConf to false, preventing WSL from auto-generating /etc/resolv.conf, so that you can create your own (ie. nameserver 1.1.1.1). [network] hostname=DemoHost generateHosts=false generateResolvConf=false # Set whether WSL supports interop processes like launching Windows apps and adding path variables. Setting these to false will block the launch of Windows processes and block adding $PATH environment variables. [interop] enabled=false appendWindowsPath=false # Set the user when launching a distribution with WSL. [user] default=DemoUser # Set a command to run when a new WSL instance launches. This example starts the Docker container service. [boot] command=service docker start ``` -------------------------------- ### Configure WSL startup commands Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/release-notes.md Use the `[boot]` section in `/etc/wsl.conf` to specify commands that run when WSL starts. ```ini [boot] command= ``` -------------------------------- ### Install WSL Plugin Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/wsl-plugins.md Installs a WSL plugin by setting a registry key. Ensure the path to the plugin DLL is correct. ```powershell Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\Plugins" -Name "demo-plugin" -Value "C:\Path\to\plugin.dll" -Force ``` -------------------------------- ### Check WSL Version Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install.md Lists installed Linux distributions and their WSL version. Use this to verify your current setup. ```powershell wsl.exe --list --verbose ``` -------------------------------- ### Install WSL with Web Download Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install.md Installs WSL and downloads the distribution package directly from the web. This is useful if the standard installation process hangs. Replace '' with the desired distribution name. Run this command in an administrator PowerShell. ```powershell wsl --install --web-download -d ``` -------------------------------- ### Install MySQL Server on Ubuntu Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Installs the MySQL server package on an Ubuntu distribution within WSL. ```bash sudo apt install mysql-server ``` -------------------------------- ### Example WSL Distribution Manifest Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/build-custom-distro.md An example of a distribution manifest showing how specific versions and their default status are defined within a flavor. ```json { "ModernDistributions": { "my-distro": [ { "Name": "my-distro-v3", "Default": true, "FriendlyName": "My distribution version 3 (latest)" "...": "..." }, { "Name": "my-distro-v2", "Default": false, "FriendlyName": "My distribution version 2" "...": "..." } ] } } ``` -------------------------------- ### Run MySQL Security Script Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Initiates the MySQL security setup script, which guides through password changes and security option configurations. ```bash sudo mysql_secure_installation ``` -------------------------------- ### Install sudo, create user, and set as default Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/use-custom-distro.md Installs necessary packages, creates a new user, adds them to the wheel group for sudo access, and configures the distribution to use this user by default. Remember to replace 'caloewen' with your desired username. ```bash yum update -y && yum install passwd sudo -y myUsername=caloewen adduser -G wheel $myUsername echo -e "[user]\ndefault=$myUsername" >> /etc/wsl.conf passwd $myUsername ``` -------------------------------- ### Install NVIDIA Runtime Packages Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gpu-compute.md Install the necessary NVIDIA runtime packages and dependencies for the NVIDIA Container Toolkit. ```bash sudo apt-get update sudo apt-get install -y nvidia-docker2 ``` -------------------------------- ### List available WSL distributions Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/release-notes.md Use `wsl --install --list-distributions` to see all available Linux distributions that can be installed on WSL. ```bash wsl --install --list-distributions ``` -------------------------------- ### Install usbipd-win using Windows Package Manager Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/connect-usb.md Install the usbipd-win project using winget. Omitting --interactive may cause an immediate restart if required. ```powershell winget install --interactive --exact dorssel.usbipd-win ``` -------------------------------- ### Install VLC Media Player Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gui-apps.md Installs VLC, a versatile free and open-source cross-platform multimedia player. Launch VLC by typing `vlc` in your Linux terminal. ```bash sudo apt install vlc -y ``` -------------------------------- ### Boot into CentOS distribution Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/use-custom-distro.md Use this command to start your imported CentOS distribution. ```PowerShell wsl -d CentOS ``` -------------------------------- ### Install WSL Distribution Package Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install-manual.md Install a downloaded Linux distribution package using the Add-AppxPackage cmdlet. This command must be run from the directory containing the .appx or .AppxBundle file. This method does not work on Server Core installations. ```powershell Add-AppxPackage .\app_name.Appx ``` -------------------------------- ### Display Docker System Information Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-containers.md Get detailed system-wide information about your Docker installation, including resource statistics and configurations relevant to the WSL 2 context. ```bash docker info ``` -------------------------------- ### Install Redis Server on Ubuntu Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Installs the Redis server package on Ubuntu. This command should be run after updating your package lists. ```bash sudo apt install redis-server ``` -------------------------------- ### Verify Docker Installation Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-containers.md After installing Docker Desktop and configuring WSL integration, use this command to check if Docker is installed correctly and display its version. ```bash docker --version ``` -------------------------------- ### Install software in Red Hat distributions using rpm Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/linux.md Alternative command for installing software on Red Hat-based distributions using rpm. Replace `` with the desired application. ```bash sudo rpo -i ``` -------------------------------- ### Install GIMP Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gui-apps.md Installs GIMP (GNU Image Manipulation Program), a powerful free and open-source raster graphics editor. Launch GIMP by simply typing `gimp` in the terminal. ```bash sudo apt install gimp -y ``` -------------------------------- ### Install WSL Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install.md Enables necessary features and installs the default Ubuntu distribution for WSL. This command should be run in an administrator PowerShell. ```powershell wsl --install ``` -------------------------------- ### Install SQLite3 on Ubuntu Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Installs the SQLite3 package on Ubuntu. This command should be run after updating your package lists. ```bash sudo apt install sqlite3 ``` -------------------------------- ### Install PostgreSQL on Ubuntu Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Installs PostgreSQL and the contrib package, which includes additional utilities, on an Ubuntu WSL distribution. ```bash sudo apt install postgresql postgresql-contrib ``` -------------------------------- ### Manage MySQL Service Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Checks the status of the MySQL service. Use 'sudo service mysql start' to start it. ```bash systemctl status mysql ``` -------------------------------- ### List Appx Contents with tar Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install-on-server.md Use tar.exe to list the contents of a downloaded Linux distribution's appx file to identify the correct installer. ```cmd > tar -xf .\debian.appx DistroLauncher-Appx_1.12.2.0_ARM64.appx DistroLauncher-Appx_1.12.2.0_scale-100.appx DistroLauncher-Appx_1.12.2.0_scale-125.appx DistroLauncher-Appx_1.12.2.0_scale-150.appx DistroLauncher-Appx_1.12.2.0_scale-400.appx DistroLauncher-Appx_1.12.2.0_x64.appx ``` -------------------------------- ### Run a Test Docker Container Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-containers.md This command runs the 'hello-world' Docker image to confirm that your Docker installation is functioning correctly and can pull and run images. ```bash docker run hello-world ``` -------------------------------- ### Example WSL 2 Port Proxy Configuration Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/networking.md This is an example of the `netsh interface portproxy` command with specific port numbers and a placeholder IP address for the WSL 2 distribution. ```powershell netsh interface portproxy add v4tov4 listenport=4000 listenaddress=0.0.0.0 connectport=4000 connectaddress=192.168.101.100 ``` -------------------------------- ### Install Google Chrome on WSL Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gui-apps.md Installs the downloaded Google Chrome .deb package, fixing any broken dependencies. The `./` specifies the current directory. ```bash sudo apt install -f ./google-chrome-stable_current_amd64.deb ``` -------------------------------- ### Update software in Ubuntu using apt Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/linux.md Run this command to update the list of available software and upgrade installed packages in Ubuntu. ```bash sudo apt update && sudo apt upgrade ``` -------------------------------- ### Open diskpart command interpreter Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/disk-space.md Start the diskpart utility with administrator privileges to manage virtual disks. ```cmd diskpart ``` -------------------------------- ### Extract and Install Linux Distribution Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install-on-server.md Extract the contents of the identified Linux distribution appx file to a specified directory and create the necessary folder structure. ```powershell $debianWSLPath = Join-Path -Path $env:LocalAppData -ChildPath DebianWSL New-Item -Path $debianWSLPath -ItemType Directory | Out-Null tar -xf .\DistroLauncher-Appx_1.12.2.0_x64.appx -C "$env:USERPROFILE\AppData\Local\DebianWSL" ``` -------------------------------- ### Select a Specific WSL Distribution Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/release-notes.md Use the --distribution option for wsl.exe to specify which installed WSL distribution to launch. ```bash wsl --distribution ``` -------------------------------- ### Run Windows notepad.exe from WSL Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/setup/environment.md Execute Windows executables directly from the WSL command line. This example opens the `.bashrc` file using Notepad. ```bash notepad.exe .bashrc ``` -------------------------------- ### Get Help for a Docker Command Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-containers.md To understand the usage and options for a specific Docker command, append '--help' to the command. ```bash docker --help ``` -------------------------------- ### List WSL Distributions Quiet Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/release-notes.md Display a concise list of installed WSL distributions. ```bash wsl.exe --list --quiet ``` -------------------------------- ### Install Git on Ubuntu/Debian Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-git.md Use this command to install the latest stable version of Git on Ubuntu or Debian-based WSL distributions. Ensure your package list is updated before running this command. ```bash sudo apt-get install git ``` -------------------------------- ### Get WSL Distribution Command Help Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/troubleshooting.md To see available commands for a specific Linux distribution, append '/?' to its executable name. ```bash C:\> ubuntu.exe /? ``` -------------------------------- ### List installed Linux distributions and their WSL version Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/basic-commands.md Shows installed Linux distributions, their running state, and the WSL version (1 or 2) they are using. This command can also be entered as `wsl -l -v`. ```powershell wsl --list --verbose ``` -------------------------------- ### Example .wslconfig file configuration Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/wsl-config.md Configure WSL 2 VM settings like memory, processors, custom kernel, swap, networking, and experimental features. Settings apply to all Linux distros on WSL 2. Ensure custom kernel paths are correct. ```bash # Settings apply across all Linux distros running on WSL 2 [wsl2] # Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB memory=4GB # Sets the VM to use two virtual processors processors=2 # Specify a custom Linux kernel to use with your installed distros. The default kernel used can be found at https://github.com/microsoft/WSL2-Linux-Kernel kernel=C:\\temp\\myCustomKernel # Specify the modules VHD for the custom Linux kernel to use with your installed distros. kernelModules=C:\\temp\\modules.vhdx # Sets additional kernel parameters, in this case enabling older Linux base images such as Centos 6 kernelCommandLine = vsyscall=emulate # Sets amount of swap storage space to 8GB, default is 25% of available RAM swap=8GB # Sets swapfile path location, default is %UserProfile%\\AppData\\Local\\Temp\\swap.vhdx swapfile=C:\\temp\\wsl-swap.vhdx # Turn on default connection to bind WSL 2 localhost to Windows localhost. Setting is ignored when networkingMode=mirrored localhostforwarding=true # Disables nested virtualization nestedVirtualization=false # Turns on output console showing contents of dmesg when opening a WSL 2 distro for debugging debugConsole=true # Sets the maximum number of crash dump files to retain (default is 10) maxCrashDumpCount=10 # Enable experimental features [experimental] sparseVhd=true ``` -------------------------------- ### Create and Open SQLite Database Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Creates a new SQLite database file named 'example.db' or opens it if it already exists. You will enter the SQLite command prompt upon execution. ```bash sqlite3 example.db ``` -------------------------------- ### List available Linux distributions for WSL Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/basic-commands.md Displays a list of Linux distributions that can be installed from the online store. This command can also be entered as `wsl -l -o`. ```powershell wsl --list --online ``` -------------------------------- ### Run WSL Command from PowerShell Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install.md Executes a WSL command directly from PowerShell. Examples include listing distributions or getting the Linux date. ```powershell wsl -l -v ``` ```powershell wsl pwd ``` ```powershell wsl date ``` -------------------------------- ### Set up Python Environment with Miniconda Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gpu-compute.md Installs Miniconda, creates a new conda environment named 'directml', and activates it. Ensure you have Python 3.7 or a compatible version. ```bash wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh conda create --name directml python=3.7 -y conda activate directml ``` -------------------------------- ### Update package lists in Linux distribution Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gui-apps.md Before installing new applications, update your distribution's package lists using this command. This ensures you get the latest available versions. ```bash sudo apt update ``` -------------------------------- ### Start WSL in the user's home directory Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/basic-commands.md Launches WSL and navigates directly to the user's home directory. Use `cd ~` from within a WSL command prompt to return to home. ```bash wsl ~ ``` -------------------------------- ### Search File Contents with grep Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/linux.md Use `cat` piped to `grep` to filter and display lines from a file that contain a specific search string. This example shows lines starting with 'P'. ```bash cat fruits.txt | grep P Pear Plum Peach ``` -------------------------------- ### Install PyTorch-DirectML Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gpu-compute.md Installs the PyTorch-DirectML package using pip after installing necessary system libraries. This enables PyTorch to use DirectML for GPU acceleration. ```bash sudo apt install libblas3 libomp5 liblapack3 pip install torch-directml ``` -------------------------------- ### Open .profile with Nano Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Opens the .profile file in the Nano text editor for modifications. Ensure you are in the root directory (`cd ~`) before running. ```bash sudo nano .profile ``` -------------------------------- ### Set the default WSL version for new installations Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/basic-commands.md Establishes the default WSL version (1 or 2) for any new Linux distributions that are installed. This setting applies to future installations. ```powershell wsl --set-default-version ``` -------------------------------- ### Display WSL Help Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/basic-commands.md Show a list of available options and commands for WSL. ```powershell wsl --help ``` -------------------------------- ### Install systemd packages on Debian/Ubuntu/Kali Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/systemd.md Ensure systemd and systemd-sysv packages are installed on Debian, Ubuntu, or Kali Rolling distributions for systemd to function correctly. This command updates package lists and installs the necessary packages. ```bash sudo apt-get update -y && sudo apt-get install systemd systemd-sysv -y ``` -------------------------------- ### Install WSL 2 Kernel Update on Windows Server 2019 Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install-on-server.md Downloads and installs the WSL 2 kernel update package for Windows Server 2019 using an MSI installer. This process requires administrator privileges. ```powershell Invoke-WebRequest -Uri "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" -OutFile ".\wsl_update_x64.msi" Start-Process "msiexec.exe" -ArgumentList "/i .\wsl_update_x64.msi /quiet" -NoNewWindow -Wait ``` -------------------------------- ### WSL Container CLI Examples Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/wsl-container.md These commands demonstrate how to use the `wslc.exe` CLI to manage Linux containers within WSL. Use these for building, running, and interacting with containers. ```powershell # Run a container wslc run --rm -it ubuntu:latest bash -c "echo Hello world from WSL container!" ``` ```powershell # List available images wslc image ls ``` ```powershell # Run a web server wslc run -it --rm -d -p 8080:80 --name web nginx ``` ```powershell # Get its content curl localhost:8080 ``` ```powershell # List the container wslc container ps ``` ```powershell # Stop the container wslc container stop web ``` -------------------------------- ### Install TensorFlow-DirectML Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gpu-compute.md Installs the TensorFlow-DirectML package using pip. This package enables TensorFlow to leverage DirectML for GPU acceleration. ```bash pip install tensorflow-directml ``` -------------------------------- ### Import a WSL Distribution in Place Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/basic-commands.md Import a specified .vhdx file as a new distribution. The virtual hard disk must be formatted with the ext4 filesystem. ```powershell wsl --import-in-place ``` -------------------------------- ### Verify Git and GCM Installation in WSL Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-git.md Run this command in your WSL distribution to check if Git and Git Credential Manager are installed and accessible. ```powershell git --version; git credential-manager --version ``` -------------------------------- ### Create a new directory Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/linux.md Use the `mkdir` command followed by a directory name to create a new directory in the current location. ```bash mkdir hello_world ``` -------------------------------- ### Set up NVIDIA Container Toolkit Repository Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gpu-compute.md Configure the stable repository for the NVIDIA Container Toolkit to enable GPU access within Docker containers. ```bash distribution=$(. /etc/os-release;echo $ID$VERSION_ID) curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-docker-keyring.gpg curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-docker-keyring.gpg] https://#g' | sudo tee /etc/apt/sources.list.d/nvidia-docker.list ``` -------------------------------- ### Check 9p Protocol Service Startup Logs Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/troubleshooting.md If you cannot access WSL files from Windows via \\wsl$, check the 9p protocol service startup logs for errors. Successful output indicates the service is running correctly. ```bash [ 0.363323] 9p: Installing v9fs 9p2000 file system support [ 0.363336] FS-Cache: Netfs '9p' registered for caching [ 0.398989] 9pnet: Installing 9P2000 support ``` -------------------------------- ### Download Ubuntu 20.04 with PowerShell Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install-manual.md Use Invoke-WebRequest to download a Linux distribution package from a given URI. The '-UseBasicParsing' flag is recommended for compatibility. ```powershell Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile Ubuntu.appx -UseBasicParsing ``` -------------------------------- ### Out-of-Box Experience (OOBE) Script for WSL Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/build-custom-distro.md A sample bash script to create a default UNIX user account for the WSL distribution. This script is intended to be used with the `oobe.command` setting in `/etc/wsl-distribution.conf` and assumes `oobe.defaultUid` is set to 1000. ```bash #!/bin/bash set -ue DEFAULT_GROUPS='adm,cdrom,sudo,dip,plugdev' DEFAULT_UID='1000' echo 'Please create a default UNIX user account. The username does not need to match your Windows username.' echo 'For more information visit: https://aka.ms/wslusers' if getent passwd "$DEFAULT_UID" > /dev/null ; then echo 'User account already exists, skipping creation' exit 0 fi while true; do # Prompt from the username read -p 'Enter new UNIX username: ' username # Create the user if /usr/sbin/adduser --uid "$DEFAULT_UID" --quiet --gecos '' "$username"; then if /usr/sbin/usermod "$username" -aG "$DEFAULT_GROUPS"; then break else /usr/sbin/deluser "$username" fi fi done ``` -------------------------------- ### Install Nautilus File Manager Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gui-apps.md Installs Nautilus, also known as GNOME Files, which serves as the file manager for the GNOME desktop. Launch it with the command `nautilus`. ```bash sudo apt install nautilus -y ``` -------------------------------- ### Install Specific WSL Distribution Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install.md Installs a specific Linux distribution for WSL. Replace '[Distro]' with the desired distribution name. Run this command in an administrator PowerShell. ```powershell wsl.exe --install -d [Distro] ``` -------------------------------- ### Copy WSL resolv.conf Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/troubleshooting.md Create a backup of the current resolv.conf file before making modifications. This is a preparatory step for manual DNS configuration. ```bash sudo cp /etc/resolv.conf /etc/resolv.conf.bak ``` -------------------------------- ### Install WSL with Microsoft Store Update Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/compare-versions.md Use this command to install the latest WSL servicing update from the Microsoft Store, beginning in Windows version 19044 or higher. ```bash wsl.exe --install ``` -------------------------------- ### WSL Distribution Configuration File Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/build-custom-distro.md Defines how the Linux distribution should be configured when first launched by the user. This file can be used to interactively create a user account or show a license agreement. ```bash # /etc/wsl-distribution.conf [oobe] command = /etc/oobe.sh defaultUid = 1000 defaultName = my-distro [shortcut] enabled = true icon = /usr/lib/wsl/my-icon.ico [windowsterminal] enabled = true ProfileTemplate = /usr/lib/wsl/terminal-profile.json ``` -------------------------------- ### List Block Devices in WSL Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/wsl2-mount-disk.md After attaching a disk with `wsl --mount --bare`, use this command inside WSL to view available block devices and their partitions. ```bash lsblk ``` -------------------------------- ### Install Gnome Text Editor Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/gui-apps.md Installs the Gnome Text Editor, the default text editor for the GNOME desktop environment. Use the command `gnome-text-editor ~/.bashrc` to launch it with your bashrc file. ```bash sudo apt install gnome-text-editor -y ``` -------------------------------- ### Import WSL Distribution Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/release-notes.md Import a WSL distribution using the --import option with version support. ```bash wsl.exe --import --version ``` -------------------------------- ### Install libnss-mdns for .local Name Resolution Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/troubleshooting.md Install the libnss-mdns package to enable hostname resolution via Multicast DNS (mDNS) for .local domains. This is necessary for resolving .local names in WSL when using Mirrored networking mode. ```bash sudo apt-get install libnss-mdns ``` -------------------------------- ### Set WSL 2 as Default Version Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/install-manual.md Run this command in PowerShell to set WSL 2 as the default version for new Linux distribution installations. This ensures new installs use WSL 2 instead of WSL 1. ```powershell wsl --set-default-version 2 ``` -------------------------------- ### Enable Hypervisor Launch Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/troubleshooting.md Run this command in an elevated PowerShell to enable the hypervisor. This is necessary for WSL 2 to function correctly. ```powershell bcdedit /set hypervisorlaunchtype Auto ``` -------------------------------- ### WSL Distribution Manifest Structure Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/build-custom-distro.md This JSON structure defines the metadata for Linux distributions available for installation via `wsl --install`. It includes details like distribution name, friendly name, and download URLs for different architectures. ```json { "ModernDistributions": { "": [ { "Name": "", "FriendlyName": "", "Default": true | false, "Amd64Url": { "Url": "", "Sha256": "" }, "Arm64Url": { "Url": "", "Sha256": "" } }, { "...": "..." } ], "": [ "..." ] } } ``` -------------------------------- ### Check PostgreSQL Version Source: https://github.com/microsoftdocs/wsl/blob/main/WSL/tutorials/wsl-database.md Verifies the installed PostgreSQL version. ```bash psql --version ```