WSL不同版本的Ubuntu更换清华镜像,加速Ubuntu软件下载速度

不同版本的Ubuntu使用清华镜像,加速Ubuntu软件下载速度

本博客目的: WSL的Ubuntu软件仓库更换清华镜像源。
提示: 这个是更新Ubuntu的软件仓库,而不是pip、conda更换清华镜像,记得自己的目的,别看错了。

使用WSL跑深度学习挺不错的,但是用wsl安装linux软件可能会存在部分问题,由于WSL里面的Ubuntu软件仓库是默认的源,有时候可能会造成网络连接问题,或者下载速度很慢,更换为清华镜像或者阿里云镜像会带来Ubuntu软件的快速下载,优化软件使用体验。

清华大学开源软件镜像站:https://mirrors.tuna.tsinghua.edu.cn/

清华大学Ubuntu软件仓库:https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/

阿里云Ubuntu软件仓库:https://developer.aliyun.com/mirror/ubuntu

该镜像仅包含32/64位x86架构处理器的软件包,在在 ARM(arm64, armhf)、PowerPC(ppc64el)、RISC-V(riscv64) 和 S390x 等架构的设备上(对应官方源为 ports.ubuntu.com)请使用 ubuntu-ports 镜像

现在的win都是64位的,对应的WSL几乎都是64位的,因此对大多人都是适应的。

1. 备份源软件配置文件

Ubuntu的系统自带的配置文件在/etc/apt/source.list中,因此我们需要首先备份该配置文件,否则删了的话,如果镜像镜像也不可用,就很难受了。

首先进入配置文件目录,如下命令:

cd /etc/apt

在这里插入图片描述

备份的命令如下,sudo表示启用管理员权限,cp表示复制,就是把后面的sources.list文件复制一份,复制的文件以source.list.bak命名。

sudo cp sources.list sources.list.bak

在这里插入图片描述

2. 复制镜像源

因为不同的Ubuntu版本对应的镜像是不同的,所以需要复制的命令也不一致,大家可以根据自己的Ubuntu版本来复制命令。他们的命令是很相似的,区别就是括号里面不一样。点击下面挑战链接,复制对应的镜像源配置。镜像速度的话,这个看地区差异,不太好说。

Ubuntu22.04 清华镜像源链接

Ubuntu23.04 清华镜像源链接

Ubuntu22.10 清华镜像源链接

Ubuntu20.04 清华镜像源链接

Ubuntu18.04 清华镜像源链接

Ubuntu16.04 清华镜像源链接

Ubuntu22.04 阿里云镜像

Ubuntu20.04 阿里云镜像

Ubuntu软件仓库:

Ubuntu 22.04 LTS (jammy)镜像源:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

Ubuntu 23.04 (lunar) 镜像源:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-proposed main restricted universe multiverse

Ubuntu 22.10 (kinetic):

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ kinetic-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ kinetic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-proposed main restricted universe multiverse

Ubuntu 20.04 (focal):

# 默认注释了源码镜像以提高 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 http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/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

Ubuntu 18.04 (bionic):

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

Ubuntu 16.04 (xenial) :

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

阿里云Ubuntu 22.04 软件仓库:

deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

阿里云Ubuntu 20.04 软件仓库:

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

3. 修改软件源配置文件

使用如下命令打开配置文件:

sudo vim sources.list

打开该文件之后,使用命令ggdG将该文件内容删除,然后按a键编辑,把复制过来的清华镜像直接右键就可粘贴。

如下所示。

保存的话,需要切换到英文输入,先Esc,然后冒号:,再按wq保存退出即可。

在这里插入图片描述

4. 更新软件包列表,升级软件包等内容

更新软件包列表代码如下,可以看到Get的地址是阿里云的镜像。

sudo apt-get update

在这里插入图片描述

升级软件包如下命令:

sudo apt-get upgrade

在这里插入图片描述

5. 从仓库中下载其它软件

直接使用命令sudo apt-get install xxx就可以安装对应的xxx软件,

如下所示:

sudo apt-get install gedit
可能存在的问题

现在的清华镜像Ubuntu软件仓库,我使用学校教育网无法连接,不知道是因为我的ip问题,还是清华镜像仓库暂时不可用的问题。

个人觉得是因为我的ip段被清华的Ubuntu软件仓库拉黑了。。。

连接问题如下:

2 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal/InRelease  Cannot initiate the connection to mirrors.tuna.tsinghua.edu.cn:443 (2402:f000:1:400::2). - connect (101: Network is unreachable) Could not connect to mirrors.tuna.tsinghua.edu.cn:443 (101.6.15.130), connection timed out
W: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal-updates/InRelease  Cannot initiate the connection to mirrors.tuna.tsinghua.edu.cn:443 (2402:f000:1:400::2). - connect (101: Network is unreachable)
W: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal-backports/InRelease  Cannot initiate the connection to mirrors.tuna.tsinghua.edu.cn:443 (2402:f000:1:400::2). - connect (101: Network is unreachable)
W: Some index files failed to download. They have been ignored, or old ones used instead.

因为使用清华镜像连接有错误,所以我现在使用阿里云镜像了。

### 数据从JSP页面传递到Servlet的方式 在Web应用程序开发中,通常会遇到需要从前端(如JSP页面)向后端(如Servlet)发送数据的情况。这可以通过表单提交、AJAX请求等方式实现。 #### 使用HTML表单提交方式 当用户填写并提交表单时,浏览器将收集所有输入字段的数据,并将其作为HTTP请求的一部分发送给服务器上的指定URL。这个URL指向的是负责处理这些数据的Servlet[^1]。 ```html <form action="processForm" method="post"> Name: <input type="text" name="name"><br> Age: <input type="number" name="age"><br> <input type="submit" value="Submit"> </form> ``` 上述代码展示了如何创建一个简单的HTML表单来获取用户的姓名和年龄信息。`action`属性指定了接收此POST请求的目标Servlet路径;而`method`则表明了使用的HTTP方法为POST。 #### 在Servlet中读取参数 为了能够接收到由前端传来的数据,在对应的Servlet类里可以重写doPost()或doGet()方法(取决于所选的方法),并通过HttpServletRequest对象访问请求中的参数: ```java protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); int age = Integer.parseInt(request.getParameter("age")); // Process the received data... } ``` 这里通过调用`request.getParameter()`函数可以根据名称提取出相应的值。对于非字符串类型的变量,则需进一步转换成适当的形式以便后续操作[^2]。 #### 利用AJAX异步传输 除了传统的同步加载外,还可以采用JavaScript技术——特别是XMLHttpRequest API 或者更现代的选择 fetch API 来发起异步请求。这种方式允许网页不重新载入的情况下更新部分内容,从而提供更好的用户体验。 下面是一个使用fetch API的例子,它展示了一个按钮点击事件触发后的动作,该动作会把一些JSON格式化的数据发往特定地址: ```javascript document.getElementById('sendDataButton').addEventListener('click', function () { const formData = new FormData(); formData.append('name', 'John Doe'); formData.append('age', 30); fetch('/processFormData', { method: 'POST', body: formData, }) .then(response => response.json()) .then(data => console.log(data)); }); ``` 这段脚本定义了一次监听器用于捕捉ID名为'sendDataButton'元素上发生的鼠标左键按下释放行为。一旦发生这样的交互活动,就会构建一个新的`FormData`实例并将两个条目加入其中。“/processFormData”代表目标资源的位置,即执行实际业务逻辑的地方。最后两行是对响应结果做简单处理的部分[^3]。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

百年孤独百年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值