windows下用WSL搭建ubuntu开发环境
WSL 安装
环境要求: windows 10 专业版。
以管理员身份打开命令行,执行安装 WSL1 :
bashdism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart安装WSL2之前需要启用虚拟机功能,执行命令:
bashdism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart重启系统。
下载 WSL2 linux内核更新包,下载完,一路默认安装。
将 WSL 2 设置为默认版本,以管理员身份打开命令行,执行命令:
bashwsl —set-default-version 2安装Ubuntu 20.04 LTS,在软件商店中下载安装。
出现问题:
bashInstalling, this may take a few minutes… WslRegisterDistribution failed with error: 0x80370114 Error: 0x80370114 ??? Press any key to continue…查看网上的教程,确保以下三项已经开启:
- 确认BIOS中已经开启虚拟化:打开任务管理器,点击“性能->CPU”会显示是否开启“虚拟化”。
- 必须安装Windows自带的虚拟机软件hyper-v、虚拟机平台:进入“设置 -> 应用 -> 可选功能 -> 更多Windows功能 ”找到并安装“hyper-v”和“虚拟机平台”完成后必须重启电脑。
- 上述功能都正常,就有可能是关闭了“虚拟化的安全”功能导致。以管理员身份打开命令行,输入命令
bcdedit /set hypervisorlaunchtype auto回车,重启电脑即可解决。
启动Ubuntu,设置用户名,密码。 (如果启动之前没有执行第6步,默认使用的WSL版本是1)
Ubuntu 换源
备份文件,命令:
sudo cp /etc/apt/sources.list /etc/apt/sources_init.list更换源,命令:
sudo vim /etc/apt/sources.list如果出现
vim: command not found,输入sudo apt-get install vim即可。阿里源:
bashdeb <http://mirrors.aliyun.com/ubuntu/> focal main restricted universe multiverse deb-src <http://mirrors.aliyun.com/ubuntu/> focal main restricted universe multiverse deb <http://mirrors.aliyun.com/ubuntu/> focal-security main restricted universe multiverse deb-src <http://mirrors.aliyun.com/ubuntu/> focal-security main restricted universe multiverse deb <http://mirrors.aliyun.com/ubuntu/> focal-updates main restricted universe multiverse deb-src <http://mirrors.aliyun.com/ubuntu/> focal-updates main restricted universe multiverse deb <http://mirrors.aliyun.com/ubuntu/> focal-proposed main restricted universe multiverse deb-src <http://mirrors.aliyun.com/ubuntu/> focal-proposed main restricted universe multiverse deb <http://mirrors.aliyun.com/ubuntu/> focal-backports main restricted universe multiverse deb-src <http://mirrors.aliyun.com/ubuntu/> focal-backports main restricted universe multiverse更新源: sudo apt-get update (Ubuntu20.04.4如果出现更新不了的情况,需要将http替换为https)
修复可能存在的损坏软件包(可选):sudo apt-get -f install
更新软件: sudo apt-get upgrade