Win10秒变Linux!WSL2安装全攻略,websocket网络通信协议。

张开发
2026/5/4 3:59:55 15 分钟阅读
Win10秒变Linux!WSL2安装全攻略,websocket网络通信协议。
安装WSL2与Ubuntu确保Windows 10版本为2004或更高或Windows 11。以管理员身份打开PowerShell运行以下命令启用WSL功能dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart启用虚拟机平台功能dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart重启计算机后将WSL2设为默认版本wsl --set-default-version 2从Microsoft Store安装Ubuntu发行版或通过命令行安装特定版本wsl --install -d Ubuntu-22.04初始化Ubuntu环境首次启动安装的Ubuntu发行版时系统会提示创建UNIX用户名和密码。此账户将被设为管理员可使用sudo命令。更新软件包列表并升级现有软件sudo apt update sudo apt upgrade -y安装基础开发工具链sudo apt install build-essential git curl wget配置WSL2与Windows集成在Windows资源管理器中访问Linux文件路径格式为\\wsl$\Ubuntu-22.04\home\username从Ubuntu访问Windows文件挂载点位于/mnt/c/Users/username配置默认登录用户替换为实际用户名ubuntu config --default-user username网络与开发环境配置WSL2使用NAT网络可通过以下命令查看IPip addr show eth0允许Windows防火墙通过WSL2网络New-NetFirewallRule -DisplayName WSL -Direction Inbound -InterfaceAlias vEthernet (WSL) -Action Allow安装常用开发环境如Node.jscurl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt install -y nodejs性能优化建议将项目文件存储在Linux根文件系统中避免放在/mnt/c下。创建符号链接快速访问常用Windows目录ln -s /mnt/c/Users/username/Projects ~/Projects调整内存限制创建或修改%UserProfile%\.wslconfig文件[wsl2] memory4GB processors2 localhostForwardingtrue常用维护命令列出已安装的发行版wsl --list --verbose终止特定发行版wsl --terminate Ubuntu-22.04导出备份发行版wsl --export Ubuntu-22.04 Ubuntu-22.04-backup.tarhttps://github.com/pjongfreemen/swc_rigp/blob/main/README.mdhttps://raw.githubusercontent.com/pjongfreemen/swc_rigp/main/README.mdhttps://github.com/ams58977/ghq_bdrshttps://github.com/ams58977/ghq_bdrs/blob/main/README.mdhttps://raw.githubusercontent.com/ams58977/ghq_bdrs/main/README.md

更多文章