在 ubuntu 22.04 上使用 apt 时 gcc 无法正确安装

在 ubuntu 22.04 上使用 apt 时 gcc 无法正确安装

我尝试通过安装脚本安装 nvidia 驱动程序,但出现错误

  ERROR: Unable to find the development tool `cc` in your      
     path; please make sure that you have the package      
     'gcc' installed.  If gcc is installed on your system, 
     then please check that `cc` is in your PATH.   

当我使用 apt 时,它说 gcc 已经安装,但是使用它没有任何返回结果。然后我决定尝试重新安装它,结果出现了这种情况,我不知道发生了什么,但是很多包都出现这种情况,我不知道该怎么办。

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 3 not upgraded.
Need to get 5,112 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 gcc amd64 4:11.2.0-1ubuntu1 [5,112 B]
Fetched 5,112 B in 0s (39.7 kB/s)
dpkg: warning: files list file for package 'libuno-cppuhelpergcc3-3' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-mingw-w64-i686-win32' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libuno-purpenvhelpergcc3-3' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libx32gcc-s1' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-mingw-w64-i686-posix' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-mingw-w64-base:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-12-base:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-12-base:i386' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-mingw-w64-i686' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-mingw-w64-i686-posix-runtime' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libx32gcc-11-dev' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-12' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'lib32gcc-s1' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-11' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-mingw-w64-i686-win32-runtime' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gdm3' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libuno-salhelpergcc3-3' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-11-multilib' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'gcc-multilib' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'lib32gcc-11-dev' missing; assuming package has no files currently installed
(Reading database ... 450000 files and directories currently installed.)
Preparing to unpack .../gcc_4%3a11.2.0-1ubuntu1_amd64.deb ...
Unpacking gcc (4:11.2.0-1ubuntu1) over (4:11.2.0-1ubuntu1) ...
Setting up gcc (4:11.2.0-1ubuntu1) ...
update-alternatives: error: alternative path /usr/bin/gcc doesn't exist
dpkg: error processing package gcc (--configure):
 installed gcc package post-installation script subprocess returned error exit status 2
Processing triggers for man-db (2.10.2-1) ...
/usr/bin/mandb: can't chmod /var/cache/man/de.UTF-8/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/de.UTF-8/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't rename /var/cache/man/de.UTF-8/15728 to /var/cache/man/de.UTF-8/index.db: Operation not permitted
/usr/bin/mandb: can't chmod /var/cache/man/de.UTF-8/index.db: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/de.UTF-8/index.db: Operation not permitted
/usr/bin/mandb: can't chmod /var/cache/man/oldlocal/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/oldlocal/CACHEDIR.TAG: Operation not permitted
Errors were encountered while processing:
 gcc
E: Sub-process /usr/bin/dpkg returned an error code (1)

编辑:问题源于我重新安装之前安装的 home、var 和 etc 文件夹。我试图避免再次重新安装,但我屈服了。

答案1

我一直使用以下方式安装这些工具

sudo apt install build-essential

该过程确保所有构建工具均可用且匹配。

如果你已经这样做了,而这是一个新问题,那么听起来你的硬件有问题。试试

fsck [/mount/point]

相关内容