哈喽,大家好,我是仲一。作为嵌入式开发程序员,常常需要在Linux环境下编译一些代码。安装虚拟机比较方便,但是,太占用内存了。性能不好的电脑开了一台虚拟机后,可能就干不了其他事情了。安装双系统也比较麻烦,常常需要重启电脑来完成系统的切换。
今天给大家介绍一款windows上的Linux工具,既不需要虚拟机也不需要双系统,就能在windows上轻松使用Linux。
WSL简介
Windows Subsystem for Linux(简称WSL)是一个为在Windows 10上能够原生运行Linux二进制可执行文件(ELF格式)的兼容层。
它是由微软与Canonical公司合作开发,目标是使纯正的Ubuntu 14.04 "Trusty Tahr"映像能下载和解压到用户的本地计算机,并且映像内的工具和实用工具能在此子系统上原生运行。
简而言之,使用WSL相当于在Windows中内嵌了一个Linux系统,它与所属的Windows系统可以互相访问本地系统,可以使用Windows的网络访问互联网,继承Windows中配置的hosts等,除了Linux GUI操作以外的其他操作,都可以在wsl中使用。
WSL当前有两个版本,WSL 1和WSL 2,目前的最新版本是2,相对于版本1,WSL 2主要的区别是提高了文件系统的性能和系统调用的兼容性。推荐使用WSL 2。
Microsoft Store安装WSL
在微软应用商店搜索 Linux,可以看到一系列 Linux 发行版,根据自己需要选择适合自己的发行版,这里我选用 Ubuntu 20.04,下载完成后启动,等待安装完成,输入账户和密码,我们便得到了一个 Linux 环境了。
WSL基本设置
配置用户名和密码
在开始菜单中打开 Ubuntu 后,Ubuntu 会进行较长时间的安装和初始化,之后会提示你设置 Linux 的用户名和密码。
更换源
更换/etc/apt/sources.list文件里的源
安装好ubuntu20.04后,默认的软件更新源是国外的,在国内使用速度很慢,需要更换成国内的源,这样才能正常安装和更新软件。
备份源列表
Ubuntu配置的默认源并不是国内的服务器,下载更新软件都比较慢。首先备份源列表文件sources.list:
复制
# 首先备份源列表
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
打开sources.list文件修改
选择合适的源,替换原文件的内容,保存编辑好的文件, 我们选择的是中科大源。
复制
# 打开sources.list文件
sudo vim /etc/apt/sources.list
编辑/etc/apt/sources.list文件, 在文件最前面添加阿里云镜像源:
复制
#中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
#添加阿里源
deb 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
#添加清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse multiverse
刷新列表
复制
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
安装SSH服务
默认情况下,首次安装Ubuntu时,不允许通过SSH进行远程访问。
大型站长资讯类网站! https://www.0817zz.com