尝试安装 g++ 编译器时出现 404 错误

尝试安装 g++ 编译器时出现 404 错误

我最近安装了 VS code,但无法下载 g++ 编译器。我输入后sudo apt install g++,它返回

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-7 g++-7 gcc gcc-7 gcc-7-base libasan4 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcilkrts5
  libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libquadmath0 libstdc++-7-dev libtsan0 libubsan0 linux-libc-dev manpages-dev
Suggested packages:
  binutils-doc cpp-doc gcc-7-locales g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg gcc-multilib make autoconf automake libtool flex bison gdb gcc-doc
  gcc-7-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan4-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg libquadmath0-dbg
  glibc-doc libstdc++-7-doc
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-7 g++ g++-7 gcc gcc-7 gcc-7-base libasan4 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0
  libcilkrts5 libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libquadmath0 libstdc++-7-dev libtsan0 libubsan0 linux-libc-dev manpages-dev
0 upgraded, 30 newly installed, 0 to remove and 0 not upgraded.
Need to get 987 kB/35.9 MB of archives.
After this operation, 155 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Ign:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-libc-dev amd64 4.15.0-29.31
Err:1 http://security.ubuntu.com/ubuntu bionic-updates/main amd64 linux-libc-dev amd64 4.15.0-29.31
  404  Not Found [IP: 91.189.88.161 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_4.15.0-29.31_amd64.deb  404  Not Found [IP: 91.189.88.161 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

我尝试运行apt-get update并尝试删除 sudo g++ 文件并重新安装它,但似乎没有任何效果。

答案1

看起来您可能需要设置正确的 DNS 服务器来解析这些 URL。

sudo vim /etc/resolv.conf

然后添加 google DNS 例如:

nameserver 8.8.4.4

之后运行 sudo apt-get update

然后继续正常安装。

答案2

首先安装你无法下载的 linux-libc-dev 包

TEMP_DEB="$(mktemp)" &&
wget -O "$TEMP_DEB" 'http://archive.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_4.15.0-49.53_amd64.deb' &&
sudo dpkg -i "$TEMP_DEB"
rm -f "$TEMP_DEB"

然后开始sudo apt-get install gcc

相关内容