安裝 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++
    

相關內容