Ubuntu嵌入式编程_超详细教程(亲自实践)
Ubuntu笔记(二) 虚拟机ubuntu20.04和树莓派4B上22.04更换国内源
本文作者Lawrence,位置未经作者允许禁止转载,谢谢!
以下所有内容,均来源于亲自实战和查询相关资料。
文章目录
前言
本文主要介绍安装好Ubuntu虚拟环境和VMwaretools后,进行换源操作,以及在树莓派4B上的换源操作,以及踩坑记录。
一、为什么换源?
Ubuntu中软件都要从一些站点去下载,这里的源可以理解为下载的服务器端对你提供的下载地址,源表明了当下载或者更新某些软件的时候要从指定的源站点去下载或者更新,使用不同的源可能会影响我们的下载速度,这里我们介绍如何更换阿里云Ubuntu 镜像的源。
二、复制源
首先我们进入阿里云的官网去下载Ubuntu的源,这里直接附上链接:
https://developer.aliyun.com/mirror/
选择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
三、更换源
1、备份原始源文件 sources.list,桌面打开终端,执行命令:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2、修改源文件sources.list
(1)终端执行命令:sudo chmod 777 /etc/apt/sources.list,更改文件权限使其可编辑;
(2)执行命令:sudo gedit /etc/apt/sources.list,打开文件进行编辑;
(3)删除原来的文件内容,复制上述的源的内容并保存。
3、sudo apt-get update
sudo apt-get install net-tools
如下图所示,表示ubuntu20.04国内源更换成功
四、树莓派4B上Ubuntu22.04换源
如果你树莓派是20.04的道理一样,以下展示Ubuntu22.04的过程。
首先大家查看自己的Ubuntu版本:差别主要在版本名上。目前主流的应该是18.04-22.04,三个版本的
可以通过指令获取到:lsb_release -a
关键地方来了,由于树莓派是arm64-Ubuntu20.04版本桌面的安装,
注意:一定是ubuntu-ports的镜像,这个才是arm版本的,不使用-ports结尾的在执行update之后会404 NOT Found ,
因此换源是加上-ports,即可,如下所示:
ubuntu 18.04(bionic) 配置如下
deb https://mirrors.aliyun.com/ubuntu-ports/ bionic main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
ubuntu 20.04(focal) 配置如下
deb https://mirrors.aliyun.com/ubuntu-ports/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu-ports/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse
ubuntu 22.04(jammy) 配置如下
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
# deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
总之,加入-ports的镜像源才是真正要换的arm版本的,那么是如何知道的呢,因为,查看换源之前.bak的文件发现原本的就是包含-ports的
总结
本文记录了Ubuntu20.04更还源的基本步骤,安装时候踩过的坑,后续所有在linux的测试都是基于此环境下进行实战演练,亲自实战,并熟练掌握,有问题欢迎大家评论并联系我,喜欢的话记得点赞哦!