This article is for who can use ‘cmd
‘ command ‘wsl
‘ after May 2019 update. Who use ‘lxrun'
should uninstall ‘lxrun
‘ and install ‘wsl
‘ first.
1. Update windows 10 to ver.2004
Please follow windows updater.
https://www.microsoft.com/en-us/software-download/windows10
1.5 Enable Virtual Machine Platform
Open ‘Turn Windows features on or off’ and check ‘Virtual Machine Platform’. Then, restart the PC.
2. Upgrade Ubuntu WSL version from 1 to 2
After windows 10 update. Do follow things.
First search ‘cmd
‘ and run ‘Command Prompt
‘ with administrator. Then type
wsl -l -v
to see your Ubuntu and WSL version before upgrade. Type
wsl --set-default-version 2
to set WSL version as 2. If you see ‘Error: 0x1bc’, update kernel by following this post https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel . Then, type
wsl --set-version Ubuntu 2
to set your Ubuntu WSL version as 2. Type
wsl -l -v
to see if it is updated.
3. Change ConEmu setting (option)
If you use ConEmu, you have to change its setting to use Ubuntu. The terminal ‘ConEmu’ will not run Ubuntu after WSL2 update. So you have to change setting. Go to ‘setting’ –> ‘Startup’ –> ‘Tasks’, select your bash on ‘Predefined tasks’ and edit ‘Commands’ as bellow.
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & wsl.exe ~ -- -cur_console:t:"Ubuntu"
Then save settings, and restart ConEmu.
4. Update Ubuntu to 20.04
Open ConEmu and type as bellow.
sudo do-release-upgrade -d
It may ask you something, I did as below:
- Use new config
- uninstall old packages
- update packages
4.5 Error
When do-release-upgrade, If you got an error like bellow
AttributeError: ‘UbuntuDistroInfo’ object has no attribute ‘version’
…
AttributeError: ‘UbuntuDistroInfo’ object has no attribute ‘get_all’
4.5 Solution
Uninstall python distro-info
python3 -m pip uninstall distro-info
sudo apt-get install python3-distro-info
and try again.
5. Check Ubuntu version
Type
lsb_release -a
to see your Ubuntu version. The result will be like below.
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
6. Set X server Display
6.1 Set correct display IP address
Due to WSL2 is Virtual Machine and Ubuntu is not running on localhost, you have to set VM’s IP to use Display. Open ~/.bashrc
and replace this line.
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
Then, reload bash by typing exec bash
.
6.2 Change Windows 10 firewall setting
Type ‘Windows Defender Firewall with Advanced Security’ in start menu to run firewall configure. In ‘Inbound Rules’, find X server problem ex. ‘VcXsrv’. You will find 4 rules, two public and two private. If two ‘public’ rules are not enabled, you have to enable them. Double click two ‘public’ rules. Check ‘Allow the connection’ in ‘Action’ and Click ‘OK’.
6.3 Start X server VcXsrv with disable access control option
When start VcXsrv, check ‘Disable access control’ in ‘Extra settings’. Or you can start it in terminal.
powershell.exe -Command '& "C:\Program Files\VcXsrv\vcxsrv.exe" -multiwindow -wgl -ac'
It is good to add below lines in ~/.bashrc
to start VcXsrv automatically.
## Start VcXsrv if not running
powershell.exe -Command '& tasklist' |
if ! grep -q vcxsrv; then
powershell.exe -Command '& "C:\Program Files\VcXsrv\vcxsrv.exe" -multiwindow -wgl -ac'
fi
That’s all.
Reference:
https://ubuntu.com/blog/ubuntu-on-wsl-2-is-generally-available
https://github.com/Maximus5/ConEmu/issues/1930
https://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+bug/1874250
https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2