Hello and welcome to this WSL2 Cheatsheet.
The goal is to gather here all tips and known issues about WSL2!
This happens when the hidden wslhost.exe
is not working. We just need to restart it!
Close all WSL2 tabs.
Open a Powershell tab and run the following command:
wsl.exe --shutdown
Check that your Ubuntu is properly stopped with the command
wsl -l -v
Open a new WSL2 Tab, problem should be fixed.
If you get this error trying to connected to your rails server
or jupyter notebook
, you need to allow the connection in Windows Defender Public rules.
Close all WSL terminal. Open a Powershell terminal and type the following command to stop all WSL processes:
wsl --shutdown Ubuntu
Hit Start and type Windows Defender Firewall
and open it.
Click on Advanced Settings
Right click on Inboud Rules and select New Rule.... Under Rule Type leave Program
selected and hit Next.
For the program, Select The program path:
and paste this path: %SystemRoot%\System32\wsl.exe
. Click on Next.
For the Action section, make sure Allow the connection
is selected and hit Next.
For the Profile section, make sure the 3 options are selected and click on Next.
Finally you will be asked to chose a name for this new rule, go with WSL - Inbound
.
Repeat the whole process by creating a Outbound Rule with the same settings, except for the name: WSL - Outbound
.
The warning Insecure world writable dir /mnt/c in PATH, mode 040777
is caused by the two differents way of Windows & Linux to deal with file permissions.
To silence those warnings:
sudo touch /etc/wsl.conf
echo '[automount]' | sudo tee -a /etc/wsl.conf > /dev/null
echo 'options="metadata,umask=0033"' | sudo tee -a /etc/wsl.conf > /dev/null
Restart all terminals.
Microsoft is slowly releasing the latest major version of Windows (version 2004). Here is the guideline if your Windows is not offering you the update.
Go to Windows 10 and under Windows 10 May 2020 Update
click on Update now. This will download a tool on your machine. Open it.
A compatibility check will start:
Next, you will be offered a choice, choose Upgrade this PC now and click on Next:
Let the tool do the work:
Microsoft is encountering some errors with the version 2004, Chances are that the update assistant will tell you that you're machine is not compatible yet!
Do not close the assistant.
Open a file explorer at this path C:\$WINDOWS.~BT\Sources\Panther
Locate the file compatscancache.dat
and delete it
Go back to the update assistant and click Refresh.
The installation should carry on.
This happens if you're using AVG antivirus. Disable AVG VPN if you're using it.
Open AVG Internet Security -> Menu - Settings - Full Protection - Enhanced firewall. Check Enable Internet connection sharing mode
On the same page, click on System Rules and enabled the first 2 options Windows file & printer sharing
Remote desktop connections
Scroll down to click on save.
Open a Powershell terminal.
Type the following command:
wsl -l -v
It will tell you the name of your WSL, it's state and version.
To switch a WSL from version 1 to 2, open a Powershell terminal.
Type the following command:
wsl --set-version Ubuntu 2
You can revert to version 1:
wsl --set-version Ubuntu 1
To access the root
session, open a Powershell terminal.
Type the following command:
wsl -d Ubuntu -u root
You can change the password of that root
session by using the command:
passwd
You will prompted to enter a new password.
Now, from your normal session, you can switch from your session to the root
on with:
su -
You will be asked for the password.
You can exit the root
session with Ctrl + D
.
Testing wont work by default on WSL2. It requires ChromeDriver and Chrome binary installed. For this we will need the root
session ( AKA The super-mega-admin-session ).
You may skip the reset of the password if you already have one for your root session.
Close all WSL2 tabs. Open a Powershell tab and run the following command:
wsl -d Ubuntu -u root
You are now login in your Ubuntu as root
.
Type the following command to change it's password:
passwd
You will be prompted twice for a new password.
Close this WSL2 tab.
Open a WSL2 tab, you should be logged in with your account. Run the following command (line per line):
sudo apt-get update
sudo apt-get install -y unzip xvfb libxi6 libgconf-2-4
We need to act as the root
session for the next command, so let's login as root (you will be prompted for the root
password):
su -
Now, let's run:
sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
sudo echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
Press Ctrl+D
to quit the root session.
If you are unsure about which session you're logged in with, you can use the whoami
command 💡.
Let's run the following commands to install Google Chrome binary and ChromeDriver on your WSL2:
sudo apt-get -y update
sudo apt-get -y install google-chrome-stable
wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver
sudo chown your-session-here:your-session-here /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
whoami
.
My result is barangerbenjamin:barangerbenjamin
.
You can now use testing in Rails. You need to open a second tab and run:
chromedriver
In the other tab you can run your tests with:
rails test:system