Ubuntu20.04换阿里源(解决安装build-essential失败问题)

2021/12/12 7:18:47

本文主要是介绍Ubuntu20.04换阿里源(解决安装build-essential失败问题),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

背景:
在Ubuntu20.04 LTS上,需要使用gcc和g++编译器编译程序,在安装build-essential时报错。如下:

acl@ubuntu:~/test$ sudo apt install build-essential
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 build-essential : Depends: libc6-dev but it is not going to be installed or
                            libc-dev
                   Depends: g++ (>= 4:7.2) but it is not going to be installed
                   Depends: dpkg-dev (>= 1.17.11) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

初步猜测是源的问题,因此将源换成阿里的源,具体步骤如下:

1 备份原来的源

cp -ra /etc/apt/sources.list /etc/apt/sources.list.bak

2 将源换成阿里源

sudo gedit /etc/apt/sources.list

然后将里面的内容清空,把下面的内容复制进去,保存退出:
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

3 更新缓存和升级

sudo apt-get update
sudo apt-get upgrade

此时阿里源已经换好。

再次安装build-essential,就会发现能安装成功了。

测试gcc和g++是否安装成功:

gcc -v
g++ -v

在这里插入图片描述



这篇关于Ubuntu20.04换阿里源(解决安装build-essential失败问题)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程