在WSL2下安装与卸载Ubuntu,更换国内源,连接GitHub
Ubuntu内核下载
链接:https://learn.microsoft.com/en-us/windows/wsl/install-manual
打开网址,找到Downloading distributions部分,然后点击相应的版本进行下载。
安装Ubuntu流程:
下载好Ubuntu安装包(.appx格式文件 | .AppxBundle请看后续介绍)后,
将安装包拖到想安装的位置(比如我是安装到E\Ubuntu\),
然后在该目录下右键,打开终端,执行以下命令(Ubuntu18.04按自己的Ubuntu版本更换一下名字):
1、重命名Ubuntu18.04文件包为.zip压缩包(在Windows下直接将改后缀为.zip也行)
Rename-Item .\Ubuntu18.04.appx Ubuntu18.04.zip
2、解压安装包
Expand-Archive .\Ubuntu18.04.zip -Verbose
3、进入解压后的文件
cd .\Ubuntu18.04\
4、执行安装程序
.\ubuntu1804.exe
(如果是22.04版本,则运行命令为 .\ubuntu.exe
)
5、安装完成后会提示输入Unix用户名和密码,之后就可以使用了。
如果Ubuntu安装包为.AppxBundle格式,则用解压缩软件打开(例如用7zip打开),按照自己CPU的架构,从中解压出相应的.appx文件,例如我解压的是x64版本。
得到.appx格式的安装包后,再按照上述的安装方式进行安装即可。
查看自己CPU架构的方法:打开cmd命令行,输入systeminfo
,即可查看。
迁移Ubuntu系统到其他盘教程:win11安装WSL2并配置Ubuntu环境 - 落樱纷飞 - 博客园 (cnblogs.com)
在WSL安装相同发行版本Ubuntu的教程请参见下面这篇:
WSL安装多个相同发行版本的Ubuntu - LesPlumes - 博客园 (cnblogs.com)
卸载Ubuntu流程:
1、查看当前环境安装的wsl
wsl --list
2、注销(卸载)当前安装的Linux的Windows子系统(名称要与list获取的一致)
wsl --unregister Ubuntu-18.04
3、卸载成功,查看当前安装的Linux的Windows子系统
wsl --list
4、然后把Ubuntu文件夹整个删除即可。
更换为国内源:
Ubuntu系统中,软件源文件地址为:/etc/apt/sources.list
1、可以将以前的源备份一下,防止后续原文件丢失:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2、打开/etc/apt/sources.list文件,在前面添加附录的国内源条目,然后把Ubuntu官方的源注释掉并保存:(可将vim更换为其他编辑器)
sudo vim /etc/apt/sources.list
3、执行命令更新源:
sudo apt-get update && sudo apt-get upgrade
通过SSH连接GitHub(参考https://zhuanlan.zhihu.com/p/423066660)
1、在本地安装Git:
sudo apt-get install git
2、配置用户信息
将Your Name替换为GitHub的登录名,注意双引号不要去掉;
将Your_email@example.com替换为GitHub的登录邮箱。
git config --global user.name "Your Name"
git config --global user.email Your_email@example.com
3、初始化本地仓库配置
git init
4、安装 SSH
sudo apt-get install ssh
5、创建密钥文件
ssh-keygen -t rsa -C "Your_email@example.com"
首先ssh-keygen会确认密钥的存储位置和文件名(默认是.ssh/id_rsa),然后他会要求你输入两次密钥口令,留空即可。所以一般选用默认,全部回车即可。
完成后会提示默认密钥文件在~/.ssh路径下,其中的id_rsa是私钥文件,id_rsa.pub是公钥文件。
6、将公钥添加到 GitHub
登录到 GitHub,点击右上角头像->Setting->SSH and GPG keys-> SSH key-> New SSH key,
然后输入:cd ~/.ssh && vim id_rsa.pub
之后会打开id_rsa.pub文件,将里面的内容全部复制并粘贴到new SSH key中。
7、SSH连接测试
输入命令:ssh -T git@github.com
如果结果为 “Hi Bro! You've successfully authenticated, but GitHub does not provide shell access”,则说明连接成功。
若提示:ssh: connect to host github.com port 22: Connection refused,大概是没关Ladder,关掉Ladder再重试即可。
附录
(Ubuntu-18.04的源,其余版本的请自行查找相应的源):
清华源:
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
中科大源:
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