2 WSL
The Windows Subsystem for Linux (WSL2) is a compatibility layer within Windows that enables users to run a Linux “core” alongside the Windows operating system. It is available for Windows 11 and recent versions of Windows 10.
WSL2 provides a seamless integration between Windows and Linux environments, allowing users to execute native Linux commands and run Linux applications directly on a Windows machine. WSL2 is designed to be compatible with the Windows filesystem, allowing you to easily interact with your Windows files.
2.1 Installing WSL2
There are detailed instructions on how to install WSL on the Microsoft documentation page. But briefly:
- Click the Windows key and search for Windows PowerShell, right-click on the app and choose Run as administrator.
- Answer “Yes” when it asks if you want the App to make changes on your computer.
- A terminal will open; run the command:
wsl --install
.
Progress bars will show while installing “Virtual Machine Platform”, “Windows Subsystem for Linux” and finally “Ubuntu” (this process can take a long time). - After installation completes, restart your computer.
- After restart, a terminal window will open asking you to create a username and password.
If it doesn’t, click the Windows key and search for Ubuntu, click on the App and it should open a new terminal.- You can use the same username and password that you have on Windows, or a different one - it’s your choice. Spaces and other special characters are not allowed for your Ubuntu username.
- Note: when you type your password nothing seems to be happening as the cursor doesn’t move. However, the terminal is recording your password as you type. You will be asked to type the new password again to confirm it, so you can always try again if you get it wrong the first time.
You should now have access to a Ubuntu Linux terminal. This behaves very much like a regular Ubuntu server.
2.2 Update essential packages
After making a fresh install of Ubuntu on WSL, it’s a good idea to update the system and install some essential packages:
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y
sudo apt install -y git
sudo apt install -y default-jre
2.3 Directory shortcuts
After installation, it is useful to create shortcuts to your directories on Windows. Your main C:\
drive is located in /mnt/c/
and other drives will be equally available based on their letter. To create shortcuts to commonly-used directories you use symbolic links.
The following commands automatically create shortcuts to your Windows “Documents”, “Desktop” and “Downloads” folders (copy/paste these commands on the terminal):
ln -s $(wslpath $(powershell.exe '[environment]::getfolderpath("MyDocuments")' | tr -d '\r')) ~/Documents
ln -s $(wslpath $(powershell.exe '[environment]::getfolderpath("Desktop")' | tr -d '\r')) ~/Desktop
ln -s $(wslpath $(powershell.exe '[environment]::getfolderpath("UserProfile")' | tr -d '\r'))/Downloads ~/Downloads
After running these commands, if you list the files in your home directory (ls -l
), you should see the shortcuts just created.
2.4 Default terminal
You can configure the Windows terminal to automatically open WSL2 (instead of the default Windows Command Prompt or Powershell):
- Search for and open the “ Terminal” application.
- Click on the down arrow in the toolbar.
- Click on “ Settings”.
- Under “Default Profile” select “ Ubuntu”.
2.5 Visual Studio Code
Visual Studio Code is a text editor which integrates very well with WSL2. Instructions to install it are given on a separate page.