为Window10 安装Linux子系统

WSL是win10 的Linux的子系统,相比虚拟机有更多的优势,对系统资源占用少,切换系统之间较为的方便。

安装步骤:

  1. 安装WSL要求Win10系统在1607版本以上,查看自己的版本是否符合要求
  2. 开启Linux子系统,控制面板>程序和功能>启用或关闭windows功能>勾选 适用于linux子系统
  3. 重启电脑
  4. 打开应用商城搜索"WSL",根据自己需求选择linux系统安装
  5. 配置linux
  6. 移动WSL的家目录位置
  7. 忘记用户密码怎么办?

下面为详细步骤

1. 查看系统版本

windows10 linux子系统安装docker win10中linux子系统_linux子系统

image-20210401113039929

一般系统版本都会符合安装要求

2.  开启Linux子系统

windows10 linux子系统安装docker win10中linux子系统_重启_02

image-20210401113316251

控制面板>程序和功能>启用或关闭windows功能>勾选 适用于linux子系统

3. 重启电脑

勾选完确定后,系统会提示重启

4. 应用商城搜索"WSL",选择安装linux系统

windows10 linux子系统安装docker win10中linux子系统_linux子系统_03

image-20210401113605980

5. 配置linux

  1. 配置好看的终端
  • 下载地址:https://github.com/felixse/FluentTerminal/releases
    下载FluentTerminal.Package_0.7.5.0.zip,解压后,右键以powershell运行,根据提示安装
  1. 更换镜像源
  • 镜像网址:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
  • 将镜像复制到sources.list中
#进入配置文件夹
cd /etc/apt
#将原来的sources.list重命名
mv sources.list sources.list.bak
#创建新的sources.list文件,并将镜像复制进去
vim sources.list
#镜像粘贴进去,:wq保存退去

#更新镜像
sudo apt-get update
  1. 配置om my zsh ,我的理解是相当于进行配置bash环境
  • 先安装zsh
sudo apt-get install zsh
  • 百度搜索oh my zsh ,找到安装命令
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

6.移动WSL的安装位置

上述在应用商城中安装会默认安装在C盘中,可能C盘内存不足了,想将安装好的Linu子系统换到D盘中。

  1. 下载LxRunOffline软件
  • 软件网址:https://github.com/DDoSolitary/LxRunOffline/releases/tag/v3.4.1
  1. 打开powershell使用软件
# 查看当前已经安装的wsl
PS G:\桌面\LxRunOffline-v3.4.0> .\LxRunOffline.exe list
Legacy
Ubuntu-18.04
 
# 移动指定的wsl
# 比如移动Legacy到Z:\LegacyWSL目录下
PS G:\桌面\LxRunOffline-v3.4.0> .\LxRunOffline.exe move -n Ubuntu-18.04 -d ‘D:\WSL\‘

7. 修改WSL(win10的linux子系统)的普通用户密码

需要在cmd中输入的命令:
1. ubuntu2004.exe config --default-user root
(注:本文使用everything去找ubuntu2004.exe是因为直接打开cmd输入以上命令会报错,
说是不能找到该文件,于是只能用这种笨办法了: )
2. bash
打开linux shell界面
3. sudo passwd wxyleo(你的用户名)
修改密码
5. exit
退出

参考资料

[1] B站:https://www.bilibili.com/video/BV1N4411F7gY?t=674