安装 g++ ubuntu 14.04 依赖:g++-4.8 (>= 4.8.2-5~) 但是它不会被安装

安装 g++ ubuntu 14.04 依赖:g++-4.8 (>= 4.8.2-5~) 但是它不会被安装

我刚刚输入:

sudo apt-get install g++

并得到:

The following packages have unmet dependencies:
 g++ : Depends: g++-4.8 (>= 4.8.2-5~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

我也按照其他论坛的建议进行了尝试:

sudo apt-get update

sudo apt-get -f install

没有人能解决我的问题。如果你知道答案,请帮忙。

编辑:

根据评论中的建议,我尝试:

sudo apt-cache policy g++-4.8

并得到以下输出:

g++-4.8:
  Installed: (none)
  Candidate: 4.8.2-19ubuntu1
  Version table:
     4.8.2-19ubuntu1 0
        500 http://ca.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

通过尝试:

sudo apt-get install g++-4.8

我有:

The following packages have unmet dependencies:
 g++-4.8 : Depends: gcc-4.8-base (= 4.8.2-19ubuntu1) but 4.8.4-2ubuntu1~14.04 is to be installed
           Depends: gcc-4.8 (= 4.8.2-19ubuntu1) but 4.8.4-2ubuntu1~14.04 is to be installed
           Depends: libstdc++-4.8-dev (= 4.8.2-19ubuntu1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

答案1

问题是:

libstdc++-4.8-dev : Depends: gcc-4.8-base (= 4.8.2-19ubuntu1) but 4.8.4-2ubuntu1~14.04 is to be installed

为什么?原因如下:

  • libstdc++-4.8-dev在主存储库中依赖于libstdc++-4.8-dev=4.8.2-19ubuntu1

  • libstdc++-4.8-dev更新存储库依赖于libstdc++-4.8-dev=4.8.4-2ubuntu1~14.04安装在您系统中的


解决方案?

我的第一选择是再次启用更新存储库:

  • 打开Software & Updates并标签Updates

  • 选择trusty-updatestrusty-security点击Close

    如果有人有该终端的版本,请告诉我。

    在此处输入图片描述

  • Reload

    在此处输入图片描述

  • 安装

    sudo apt-get install g++
    

我的第二选择,降级

嗯,我想说,这是个坏主意=)

答案2

因为源的Ubuntu 14.04太旧或者无法访问,所以需要更新源,这样就可以解决了,首先需要备份源文件sources.list

sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

根据Ubuntu的版本添加新的源。

  1. 查询版本命令:

    lsb_release -a
    

    然后它将打印如下信息:

    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 14.04.4 LTS
    Release:    14.04
    Codename:   trusty
    
  2. 根据版本选择合适的源并添加到/etc/apt/sources.list文件末尾。

    http://wiki.ubuntu.org.cn/Template:14.04source,
    

    Ubuntu 14.04 源:

    deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
    
  3. 更新源

    sudo apt-get update
    
  4. 好的

    sudo apt-get install g++
    

相关内容