在 Windows 10 中的 Ubuntu shell 中尝试安装 g++ 时出错

在 Windows 10 中的 Ubuntu shell 中尝试安装 g++ 时出错

从 Windows 商店下载 Ubuntu 应用程序后,我尝试运行 gcc --version,结果显示command gcc not found情况相同g++

我尝试使用安装 sudo apt install gcc,但它一直显示类似以下错误

Err:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 binutils-common amd64 2.30-21ubuntu1~18.04.1 404 Not Found

最后它给了我这个

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

我已经尝试过的方法:-

  1. 我遇到了这个Bash(在 Windows 10 上)找不到任何包我按照那里说的做了,然后我运行了更新命令,然后运行了sudo apt install gcc命令。它确实安装了 gcc,我用它检查了gcc --version。但是当我运行“sudo apt 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.

  1. 我的问题被识别为可能重复无法纠正问题,您持有破损的包裹,但结果证明这毫无帮助。当我运行命令dpkg --get-selections | grep hold来查找保留的软件包列表时,我什么也没得到。我再次尝试使用sudo aptitude install g++它,得到了这个作为输出。
   The following actions will resolve these dependencies:
      Remove the following packages:
1)      bind9-host
2)      cloud-init
3)      dnsutils
4)      initramfs-tools-core
5)      landscape-common
6)      libbind9-160
7)      libcom-err2
8)      libcurl4
9)      libdns1100
10)     libext2fs2
11)     libirs160
12)     libisccfg160
13)     python3-cryptography
14)     python3-oauthlib
15)     python3-openssl
16)     python3-service-identity
17)     python3-twisted
18)     ureadahead
      Install the following packages:
19)     e2fslibs [1.42.9-3ubuntu1.3 (trusty-updates)]
20)     insserv [1.14.0-5ubuntu2 (trusty)]
21)     knot-dnsutils [1.4.2-1 (trusty)]
22)     libck-connector0 [0.4.5-3.1ubuntu2 (trusty)]
23)     libcomerr2 [1.42.9-3ubuntu1.3 (trusty-updates)]
24)     libcurl3 [7.35.0-1ubuntu2.20 (trusty-security, trusty-updates)]
25)     libgcrypt11 [1.5.3-2ubuntu4.6 (trusty-security, trusty-updates)]
26)     libgnutls26 [2.12.23-12ubuntu2.8 (trusty-security, trusty-updates)]
27)     librtmp0 [2.4+20121230.gitdf6c518-1ubuntu0.1 (trusty-security, trusty-updates)]
28)     module-init-tools [15-0ubuntu7 (trusty-security, trusty-updates)]
29)     sysv-rc [2.88dsf-41ubuntu6.3 (trusty-updates)]
      Keep the following packages at their current version:
30)     g++ [Not Installed]
31)     g++-4.8 [Not Installed]
32)     libc-dev-bin [Not Installed]
33)     libc6-dev [Not Installed]
34)     libstdc++-4.8-dev [Not Installed]
      Downgrade the following packages:
35)     curl [7.58.0-2ubuntu3.6 (now) -> 7.35.0-1ubuntu2.20 (trusty-security, trusty-updates)]
36)     e2fsprogs [1.44.1-1ubuntu1.1 (now) -> 1.42.9-3ubuntu1.3 (trusty-updates)]
37)     git [1:2.17.1-1ubuntu0.4 (now) -> 1:1.9.1-1ubuntu0.10 (trusty-security, trusty-updates)]
38)     git-man [1:2.17.1-1ubuntu0.4 (now) -> 1:1.9.1-1ubuntu0.10 (trusty-security, trusty-updates)]
39)     initramfs-tools [0.130ubuntu3.7 (now) -> 0.103ubuntu4.11 (trusty-updates)]
40)     initramfs-tools-bin [0.130ubuntu3.7 (now) -> 0.103ubuntu4.11 (trusty-updates)]
41)     libcurl3-gnutls [7.58.0-2ubuntu3.6 (now) -> 7.35.0-1ubuntu2.20 (trusty-security, trusty-updates)
42)     libgssapi-krb5-2 [1.16-2ubuntu0.1 (now) -> 1.12+dfsg-2ubuntu5.4 (trusty-security, trusty-updates
43)     libk5crypto3 [1.16-2ubuntu0.1 (now) -> 1.12+dfsg-2ubuntu5.4 (trusty-security, trusty-updates)]
44)     libkrb5-3 [1.16-2ubuntu0.1 (now) -> 1.12+dfsg-2ubuntu5.4 (trusty-security, trusty-updates)]
45)     libkrb5support0 [1.16-2ubuntu0.1 (now) -> 1.12+dfsg-2ubuntu5.4 (trusty-security, trusty-updates)
46)     libss2 [1.44.1-1ubuntu1.1 (now) -> 1.42.9-3ubuntu1.2 (trusty-security)]
47)     manpages [4.15-1 (now) -> 3.54-1ubuntu1 (trusty)]
48)     openssh-client [1:7.6p1-4ubuntu0.3 (now) -> 1:6.6p1-2ubuntu2.13 (trusty-security, trusty-updates
49)     openssh-server [1:7.6p1-4ubuntu0.3 (now) -> 1:6.6p1-2ubuntu2.13 (trusty-security, trusty-updates
50)     openssh-sftp-server [1:7.6p1-4ubuntu0.3 (now) -> 1:6.6p1-2ubuntu2.13 (trusty-security, trusty-up
      Leave the following dependencies unresolved:
51)     python3-incremental recommends python3-twisted
52)     python3-jwt recommends python3-cryptography
53)     ubuntu-standard recommends ureadahead

我按了 Y 然后

E: The method driver /usr/lib/apt/methods/http could not be found.
E: The method driver /usr/lib/apt/methods/http could not be found.
E: Internal error: couldn't generate list of packages to download
  1. 我通过重置应用程序重新开始,然后运行命令sudo apt update,它显示了这个
Reading package lists... Done
E: Release file for http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease is not valid yet (invalid for another 4h 13min 23s). Updates for this repository will not be applied.
E: Release file for http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease is not valid yet (invalid for another 4h 12min 44s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease is not valid yet (invalid for another 4h 14min 2s). Updates for this repository will not be applied.

我还想说一下,我是这个 Linux 环境的初学者,所以如果你能解释一下你的答案,那将会非常有帮助

答案1

问题是(正如@steeldriver 所说)我的系统时间没有同步。也许我的 CMOS 电池没电了,导致 4 小时的延迟。所以每当我尝试更新时,它都会显示错误。因此,在同步我的时间并运行

sudo apt update
sudo apt install g++
sudo apt install gcc

它成功安装了 g++ 和 gcc。

相关内容