在Windows安装Liunx

Liunx For Windows简介和安装

参考连接
https://www.linuxidc.com/Linux/2017-10/147961.htm

WSL对比虚拟机

优点:
系统耗费资源更少
win10一开机,liunx子系统也跟着开机,无痛
缺点:
wsl要重启必须重启win10,调用shutdown指令被拒绝
安装在C盘,强迫症难受

WSL安装好的第一件事:配置软件源

  1. 备份原始文件
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
  2. 通过vi设置软件源
    sudo vi /etc/apt/sources.list
#阿里云
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

#网易163
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse

有可能遇到部分软件安装不了的问题,可以更换回官方源,我之前设置的阿里源,貌试就装不了g++,回来改回官方源才装上的

WSL安装好的第二件事:安装配置SSH

  1. 安装服务
    sudo apt install openssh-server
  2. 修改配置文件
    sudo vim /etc/ssh/sshd_config
    用来修改
  3. 生成密钥
    ssh-keygen -t rsa -P ‘’ -f ~/.ssh/id_rsa
  4. 启动服务
    sudo service ssh restart

WSL安装好的第三件事:搭建VS开发环境

vs工作负载中勾选使用C++的Liunx开发

在Windows安装Liunx_第1张图片

创建Liunx工程

在Windows安装Liunx_第2张图片

通过ssh连接到WSL

在Windows安装Liunx_第3张图片

编译运行项目

	1、WSL中安装g++和gdb
	2、alt+f5,vs将自动编译项目并生成文件拷贝到wsl
	3、在wsl中找到输出文件运行即可
	4、或者直接在VS中调试按f5
	5、vs会在将程序输入输出传输到vs的控制台,并可以像普通的vs工程一样单步调试和堆栈信息查看

ps:
1、对于编译选项和运行选项可以在vs中直接配置
2、初次使用会拷贝wsl中的标头文件,可能会花几分钟,标头拷贝完成会关闭标头同步,那以后的liunx工程就会共用一套标头

你可能感兴趣的:(WSL,Windows子系统,C++,SSH)