在 Ubuntu 上安装 G++ 时出错

在 Ubuntu 上安装 G++ 时出错

嗨,我想知道如何修复 g++ 并构建必需品。它一直在说:

Setting up g++ (4:8.2.0-1ubuntu1) ...
update-alternatives: error: /var/lib/dpkg/alternatives/c++ corrupt: invalid status
dpkg: error processing package g++ (--configure):
 installed g++ package post-installation script subprocess returned error exit status 2
dpkg: dependency problems prevent configuration of build-essential:
 build-essential depends on g++ (>= 4:7.3); however:
  Package g++ is not configured yet.

现在我无法安装任何东西

$ sudo apt-get install g++
Reading package lists... Done
Building dependency tree       
Reading state information... Done
g++ is already the newest version (4:8.2.0-1ubuntu1).
The following packages were automatically installed and are no longer required:
  fprintd gir1.2-accountsservice-1.0 gir1.2-gck-1 gir1.2-gcr-3
  gir1.2-gdesktopenums-3.0 gir1.2-gdm-1.0 gir1.2-gnomebluetooth-1.0
  gir1.2-gnomedesktop-3.0 gir1.2-gweather-3.0 gir1.2-nm-1.0 gir1.2-nma-1.0
  gir1.2-rsvg-2.0 gir1.2-upowerglib-1.0 gjs glib-networking:i386
  gnome-control-center-faces gnome-shell-common gnome-todo-common libargon2-0
  libaspell15:i386 libatk-bridge2.0-0:i386 libatk1.0-0:i386 libatspi2.0-0:i386
  libboost-date-time1.65.1 libboost-locale1.65.1 libboost-thread1.65.1
  libbrotli1:i386 libcairo-gobject2:i386 libcamel-1.2-61 libcolord-gtk1
  libcolord2:i386 libcomerr2:i386 libdatrie1:i386 libdazzle-1.0-0
  libdns-export1100 libebook-1.2-19 libedata-cal-1.2-29 libenchant1c2a:i386
  libepoxy0:i386 libfprint0 libfribidi0:i386 libgdk-pixbuf2.0-0:i386 libgdm1
  libgjs0g libglvnd0:i386 libgnome-todo libgraphene-1.0-0 libgraphite2-3:i386
  libgudev-1.0-0:i386 libharfbuzz-icu0:i386 libharfbuzz0b:i386
  libhunspell-1.6-0:i386 libhyphen0:i386 libjson-glib-1.0-0:i386 liblouis14
  libmagickcore-6.q16-3 libmagickcore-6.q16-3-extra libmagickwand-6.q16-3
  libmozjs-60-0 libnotify4:i386 libpam-fprintd libpango-1.0-0:i386
  libpangocairo-1.0-0:i386 libpangoft2-1.0-0:i386 libpoppler73 libprocps6
  libproxy1v5:i386 libpsl5:i386 libraw16 librest-0.7-0:i386 libsecret-1-0:i386
  libsoup-gnome2.4-1:i386 libsoup2.4-1:i386 libspeexdsp1:i386 libstdc++-7-dev
  libsysmetrics1 libthai0:i386 libwebpdemux2:i386 libwoff1:i386 libxcb-res0
  libxkbcommon0:i386 linux-headers-4.15.0-44 linux-headers-4.15.0-44-generic
  linux-image-4.15.0-44-generic linux-modules-4.15.0-44-generic
  linux-modules-extra-4.15.0-44-generic mutter-common nplan
  python3-macaroonbakery python3-nacl python3-protobuf python3-pymacaroons
  python3-rfc3339 python3-tz switcheroo-control xwayland
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up g++ (4:8.2.0-1ubuntu1) ...
update-alternatives: error: /var/lib/dpkg/alternatives/c++ corrupt: invalid status
dpkg: error processing package g++ (--configure):
 installed g++ package post-installation script subprocess returned error exit status 2
dpkg: dependency problems prevent configuration of build-essential:
 build-essential depends on g++ (>= 4:7.3); however:
  Package g++ is not configured yet.

dpkg: error processing package build-essential (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
 g++
 build-essential
E: Sub-process /usr/bin/dpkg returned an error code (1)

dpkg: error processing package build-essential (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 g++
 build-essential

答案1

这看起来非常类似于这。我在这里修改了接受的答案:

替代条目已损坏。

  1. 您应该使用以下方法删除它们:

    sudo update-alternatives --remove-all c++
    sudo rm -f /etc/alternatives/c++ /var/lib/dpkg/alternatives/c++
    

    如果update-alternatives再次抱怨文件损坏,请忽略它并继续使用下一个命令删除它们。

  2. 使用以下方法重新安装依赖项sudo apt-get -f install

  3. 然后使用以下命令重新安装其软件包:

    sudo apt-get install --reinstall c++
    

    这将根据您的系统上可用的软件包恢复替代条目。

  4. 对任何其他损坏的条目执行类似操作。

相关内容