2022年2月 windows10+wsl2+Debian+切换安装目录+换源基本设置
作者:互联网
1.windows 安装wsl2和debian
此处使用windows10专业版最新版,刚装的电脑没有特意开启过任何东西。
以下powershell命令都需要使用管理员方式启动,快捷键:win+x再按a
1.1 安装wsl2和debian
wsl --install -d Debian
下载完按提示设置普通用户的用户名密码即可
1.2 修改root密码
# powershell中输入 设置进入root用户
Debian config --default-user root
# 进入wsl系统 输入此命令按提示修改密码
passwd
# powershell 设置回普通用户(admin为我的普通用户用户名)
Debian config --default-user admin
1.3 迁移所在目录到其他盘
# 关闭wsl系统 导出wsl系统成tar文件并存放再E盘下 再取消挂载debian
wsl --shutdown
wsl --export Debian E:\Debian.tar
wsl --unregister Debian
# 重新挂载debian到e盘wsl2目录下
wsl --import Debian E:\wsl2\Debian E:\Debian.tar
之后从开始菜单中再次运行debian即可
2.换源
此处有个坑,以前用的debian10是默认支持https的,wsl默认安装的版本是debian9,如果要使用带https的源(比如华为源)需要手动安装一些依赖。(但是你不更新源你就下载不了https支持的依赖,想下载依赖你又要更新源……所以此处选择纯http的163源进行安装,后续可以再换成需要https支持的源)
debian9国内镜像的地址可参考:https://www.cnblogs.com/liuguanglin/p/9397428.html
#输入第一行命令后 复制粘贴后续几行的内容
cat > /etc/apt/sources.list <<EOF
deb http://mirrors.163.com/debian/ stretch main non-free contrib
deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.163.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib
EOF
#此处不clean的话可能会出现 0% working的问题,再输入一次apt-get clean即可
apt-get clean
apt-get update
此处会报一个异常 似乎是需要更新证书
Reading package lists... Done
W: GPG error: http://mirrors.163.com/debian stretch-backports InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 648ACFD622F3D138 NO_PUBKEY 0E98404D386FA1D9
W: The repository 'http://mirrors.163.com/debian stretch-backports InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
#先安装命令需要的依赖
apt-get install software-properties-common dirmngr -y
#此处后面一大长串为你报错信息里的
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com XXXXXXXXXXXXXXXX
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com XXXXXXXXXXXXXXXX
apt-get clean
#如果出现0% working卡住了就重新来一遍apt-get clean 再apt-get update
apt-get update
如果需要再切换到https源,可以
apt-get install apt-transport-https -y
cat > /etc/apt/sources.list <<EOF
> deb https://mirrors.huaweicloud.com/debian/ stretch main contrib non-free
> deb-src https://mirrors.huaweicloud.com/debian/ stretch main contrib non-free
> deb https://mirrors.huaweicloud.com/debian/ stretch-updates main contrib non-free
> deb-src https://mirrors.huaweicloud.com/debian/ stretch-updates main contrib non-free
> deb https://mirrors.huaweicloud.com/debian/ stretch-backports main contrib non-free
> deb-src https://mirrors.huaweicloud.com/debian/ stretch-backports main contrib non-free
> EOF
到此所有工作全部完成
标签:--,com,windows10,apt,Debian,换源,https,wsl2,debian 来源: https://blog.csdn.net/zongjinyun123/article/details/122777039