我参考了以下两个链接尝试成功总结的,感谢!:
https://blog.csdn.net/qq_41286751/article/details/125540832?spm=1001.2014.3001.5502
https://blog.csdn.net/qq_41286751/article/details/125557165?spm=1001.2014.3001.5506
原因:Ubuntu镜像源不对
确保换的源,跟安装的Ubuntu系统版本匹配!
比如ubuntu22.04应该换jammy源,其他的版本还有focal源等。
通过查看系统版本命令可以看到:
lsb_release -a
查看到版本后就可以开始换源
1.备份系统的源(略)
2.使用gedit编辑文件换源
代码如下:
sudo gedit /etc/apt/sources.list
2.然后从网上找相应的源(阿里源,清华源等)
注意看源中的是focal、bionic等。
3.换源(jammy为例,其他的网上找)
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse# deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
复制上述代码到sources文件中去。
执行下面两个命令:
sudo apt-get update
#这个命令,会访问源列表里的每个网址,并读取软件列表,然后保存在本地电脑。我们在新立得软件包管理器里看到的软件列表,都是通过update命令更新的。
sudo apt-get upgrade
#这个命令,会把本地已安装的软件,与刚下载的软件列表里对应软件进行对比,如果发现已安装的软件版本太低,就会提示你更新。如果你的软件都是最新版本,会提示:
#升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
没有报错就行了,正常安装gcc等。