Use a batch script with wsl --install -d Ubuntu-24.04 to automate WSL installation on Windows 10 and 11. This method handles feature enabling and distro download silently, requiring no manual clicks during the process for a seamless setup experience.
Prerequisites for Automated Installation
Before creating your automation script, ensure your environment is ready. The commandwsl --install works best on Windows 10 version 2004 and higher, or Windows 11. If you are running an older build, you may need to update your OS first. For users facing issues on server environments, check out our guide on how to handle Unable to install WSL distribution on Windows 2019, as server versions often require different permission levels.
You must run your batch file with Administrator privileges. The script needs to enable virtual machine features and the Windows Subsystem for Linux capability, which standard user accounts cannot do without elevation. Additionally, ensure that your system has internet access, as the installer downloads the specific Linux distribution package from Microsoft’s servers.
Creating the Batch Script
Open Notepad or any text editor on your Windows machine. You will create a simple batch file that executes the necessary commands in sequence. Copy the following code block into your editor:@echo off
title Installing WSL and Ubuntu 24.04
echo Starting automated WSL installation...
REM Enable required components
wsl --install -d Ubuntu-24.04
echo Installation complete. Please restart your computer.
pause
Save this file with a .bat extension, such as install_wsl.bat. The @echo off line keeps the console clean by hiding the individual command echoes, showing only your custom messages. The title command sets the window header for better visibility in Task Manager if needed.
The core command is wsl --install -d Ubuntu-24.04. The -d flag specifies the distribution name. While Ubuntu is the default, specifying Ubuntu-24.04 ensures you get the latest Long Term Support release available at the time of execution. This command automatically enables the "Windows Subsystem for Linux" and "Virtual Machine Platform" optional components if they are disabled. It also sets WSL 2 as the default version.
Handling Output and Errors
If the script fails, it is usually due to insufficient permissions or network issues. To make debugging easier, you can remove@echo off temporarily. This will show you exactly which step failed. Common errors include the "WSL not installed" message, which indicates your Windows version is too old, or timeout errors if the download fails.
For more advanced scenarios where you want to import an existing rootfs rather than downloading a new one, consider reading about the WSL --import-in-place Command. However, for most fresh installations, the standard --install method is faster and less prone to configuration errors.
Executing the Script
Locate your savedinstall_wsl.bat file. Right-click on it and select "Run as administrator." A User Account Control (UAC) prompt will appear; click Yes to allow administrative changes. The command prompt window will open, displaying the progress of the installation.
You will see output indicating that components are being enabled. This process may take a few minutes depending on your internet speed. Once the download finishes, the script will display "Installation complete. Please restart your computer." Do not skip the restart. WSL requires a reboot to finalize the kernel updates and component registrations.
After restarting, open PowerShell or Command Prompt and type wsl. The system should automatically launch Ubuntu 24.04 and prompt you to create a UNIX username and password. This confirms that the automated installation was successful.