如何在WSL(Windows子系统Linux)上安装GCC和GDB?

24

我需要gcc来编译C代码,但无法在WSL上安装gcc。我尝试了sudo apt-get install gcc,但它没有起作用。这是错误信息。

hack@DESKTOP-VMQA3JB:~$ sudo apt-get install gcc
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc : Depends: gcc-9 (>= 9.2.1-1~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

我不知道要安装哪些依赖项。请帮我解决gdb问题。谢谢。


1
在运行了 sudo apt-get updatesudo apt-get upgrade 之后,您还有这个问题吗? - Brecht Sanders
是的,在更新和升级后它起作用了。谢谢! - Aravind Emmadishetty
1个回答

61

您需要:

  1. 更新和升级:
$ sudo apt-get update && sudo apt-get upgrade -y

这里输入图片描述

2. 清除不需要的软件包:

$ sudo apt autoremove -y

输入图像描述

  1. 安装GCC:
$ sudo apt-get install gcc -y

enter image description here

  1. 检查并确认已安装的gcc版本:
gcc --version

这里输入图片描述


3
您好,我了解您的疑问。在“sudo apt-get upgrade -y”中,“-y”的意思是自动回答“yes”以进行确认操作,而不需要在每个提示处手动输入“yes”。 - Parting
8
意思是回答“y”(即yes)表示同意并确认继续进行任何需要确认的问题。 - Hasan A Yousef

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接