Window下安装Ubantu18.04子系统并连上VSCode

1、打开适用于Linux的Windwos子系统选项

控制面板->程序->启用或关闭Window功能->适用于Linux的Windwos子系统选项

2、下载Ubantu并安装

Window10版本中,打开应用商店,搜索Ubantu18.04下载,并安装。

注:若提示所在地区无法下载,则设置国家或地区为美国。具体操作如下:设置->时间和区域->区域->国家或地区中选择美国。

3、安装Ubantu18.04

安装时会提示输入用户名和密码

4、更改Ubantu18.04镜像源

备份/etc/apt/sources.list
#备份
cp /etc/apt/sources.list /etc/apt/sources.list.bak

在/etc/apt/sources.list文件前面添加如下条目
#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

最后执行如下命令更新源
##更新
sudo apt-get update
sudo apt-get upgrade

5、VSCode连接Ubantu子系统

打开VSCode(该VSCode是安装在Window下的),下载插件Remote - WSL

6、Ubantu子系统启动VSCode

1、打开Ubantu18.04

注:Window下的C盘内容默认是挂载在/mnt目录下的

2、确定需要创建的文件位置,并输入code . 启动VSCode

3、首次连接成功后,下一次连接时,直接打开VSCode,点击Remote Explorer,点击目标文件

 

猜你喜欢

转载自blog.csdn.net/qq_33457548/article/details/105726240