WSL Instructions for Use
About uninstalling
-
wsl --shutdown
-
wsl --unregister xxxxx
- Uninstall
Ubuntu
On
Windows
function off:-
Windows
subsystem forLinux
bc6031ce0e94e8456a5119a773481e67--- - Virtual machine platform
-
- Click OK
About import and export
import
andexport
are only for the disk, which means that the modification mentioned on the InternetUbuntu
the import and export method of the directory is to modify the location of the disk.
The following is the operation when migratingUbuntu
:wsl --export Ubuntu E:\Wsl\Ubuntu\ubuntu.tar wsl --unregister Ubuntu wsl --import Ubuntu E:\Wsl\Ubuntu E:\Wsl\Ubuntu\Ubuntu.tar --version 2
About user permissions
- When you start
Ubuntu
for the first time, it will ask you to create a user, which is the user set below. It can be a good solution to create a file underWindwos
withRoot
permission problem, andVscode
inTerminal
can also be opened Ordinary users do not need to set up. Execute the following command in
cmd
orpowershell
ubuntu config --default-user xxx # wsl 关闭 wsl --terminate Ubuntu # wsl 启动 -u 指定用户 wsl -d Ubuntu -u xxx
About the agent
For proxy problems, be sure to develop proxy software that allows LAN. After that, find the proxy port of the LAN.
Settings: source proxy.sh set 10811
Unset: source proxy.sh unset
#!/bin/sh
hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
wslip=$(hostname -I | awk '{print $1}')
set_proxy(){
PROXY_HTTP="http://${hostip}:${port}"
PROXY_HTTPS="http://${hostip}:${port}"
export http_proxy="${PROXY_HTTP}"
export HTTP_PROXY="${PROXY_HTTP}"
export https_proxy="${PROXY_HTTPS}"
export HTTPS_PROXY="${PROXY_HTTPS}"
export all_proxy="${PROXY_HTTP}"
export ALL_PROXY="${PROXY_HTTP}"
echo "Host ip:" ${hostip}
echo "WSL ip:" ${wslip}
echo "Current http proxy: ${PROXY_HTTP}"
echo "Current https proxy: ${PROXY_HTTPS}"
echo "Note: You need to invoke this command with source, like: source proxy.sh set ${port}"
}
unset_proxy(){
unset http_proxy
unset HTTP_PROXY
unset https_proxy
unset HTTPS_PROXY
unset ALL_PROXY
unset all_proxy
echo "Unset done: http_proxy HTTP_PROXY https_proxy HTTPS_PROXY"
echo "Note: You need to invoke this command with source: source proxy.sh unset"
}
proxy_info(){
echo "Host ip:" ${hostip}
echo "WSL ip:" ${wslip}
echo "Current http proxy: $http_proxy"
echo "Current https proxy: $https_proxy"
}
if [ "$1" = "set" ]
then
if [ "$2" = "" ]
then
port="10809"
echo "Use default port: ${port}"
else
port="$2"
fi
set_proxy
elif [ "$1" = "unset" ]
then
unset_proxy
elif [ "$1" = "info" ]
then
proxy_info
else
echo "Unsupported arguments: $1. Available aguments: set [port] unset info"
fi
About IDEA
idea
wsl2
is unbearable! I hope you can send an announcement to let me know that it can be used after you change it.
I've run into a lot of problems these days:
1, wsl2
The files created by ordinary users cannot be opened.
2. Ordinary users who cannot switch to wsl2
idea
go up.
3. idea
check every time jdk
, even if it is fine after the first check. Extremely slow.
4, apt install
installed maven
cannot be recognized.
5. It is especially easy to get stuck and crash!
About development
Note: wsl2
is not recommended to call across system files. We consider the following scenarios.
- To use
wsl
as a server only requireswsl
as a server, and the code is developed locally.
In this way, you need to copy a copy of the local code to thewsl
directory. The code can only be deployed in the form of file upload. Even in your opinion, it's all onwindows
, unfortunately, because it is not recommended to access files across systems, how accurate is this not recommended? Basically, onels
will be stuck for a while. . .
Also, it can only be developed inwindows
, and there will be network problems remotely. - The development environment all uses the
wsl
directory,idea
does not support,vscode
indicates that the adaptation is very good. The remote development ofjetbrains
vscode
is similar to that of ---0c873f9f47a890deec26e4327c77998f--- and can be used.
Simply put, it is remote development. Even if you feel that they are all on yourwindows
, they are actually far away. . . - I don't know what to say. It's all in
windows
, please closewsl2
this garbage.
About the network
All services in wsl2
can only be accessed locally. If you want to provide remote access, you need to let windows
forward.
Two commands are involved:
netsh interface portproxy add v4tov4 listenport=[port] listenaddress=0.0.0.0 connectport=[port] connectaddress=[wsl ip]
netsh.exe advfirewall firewall add rule name=WSL2 dir=in action=allow protocol=TCP localport=[port]
One tells windows
forward wsl
service port. A windows
open firewall
About docker
It's fun to play, but you can't provide remote services due to network reasons.
Summarize
- If the disk and network problems are not solved, please don't use
wsl2
, it is better to open a virtual machine. - It is recommended to develop locally in
windows
, which is installed. Don't think about usingwsl2
to isolate the development environment.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。