如何在……上安装 GCC 编译器 Windows
⚡ 智能摘要
Download and Install GCC Compiler in C for Windows,Linux和 macOS in under fifteen minutes. The Code::Blocks bundle on Windows ships GCC, an editor, and a debugger together, while Linux and macOS users install GCC directly through their package managers.

什么是海合会?
此 GCC (GNU Compiler Collection) is a free, open-source compiler suite maintained by the Free Software Foundation. It supports C, C++,Objective-C, Fortran, Ada, Go, and several other languages, and is the default compiler on most Linux distributions. GCC produces fast, portable executables and is the standard choice for learning C on Windows,Linux和 macOS.
This tutorial walks through installing GCC on each platform and verifying the installation with a simple version check.
如何在 Windows
On Windows the easiest path is the open-source IDE Code::积木, which bundles a 编译 (GCC from the GNU Project), an 编辑,以及 调试器 in a single installer.
Step 1) Download the Binary Release
在MyCAD中点击 软件更新 https://www.codeblocks.org/downloads/ 并点击 Binary Release.
Step 2) Choose the installer with the GCC compiler
Pick the installer that bundles the GCC compiler — for example, codeblocks-17.12mingw-setup.exe. This package includes MinGW’s GNU GCC compiler and the GNU GDB debugger together with the Code::阻止源文件。
步骤3)开始安装
Run the downloaded installer and accept the default options. This straightforward process sets up the GCC compiler on your Windows 系统。
Step 4) Accept the licence agreement
Accept the licence agreement to continue.
Step 5) Keep the default component selection
Leave the component selection at its default and click 下一篇.
Step 6) Choose the installation path
Change the installation folder if you wish, then click 下一篇.
步骤 7) 启动 Code::积木
找到 Code::Blocks shortcut on your desktop or Start menu and double-click it.
Step 8) Let Code::Blocks detect the compiler
首次发射时, Code::Blocks scans for installed compilers, detects GCC automatically, and sets it as the default. Associate C and C++ 文件用 Code::Blocks when prompted.
Step 9) Open the IDE and start coding
The IDE home screen appears. You can now create a new C project and compile your first program.
How to Install GCC on Linux
Most Linux distributions ship with GCC pre-installed. Verify with:
gcc --version
If GCC is present, the command prints its version. If it is missing, the shell prompts you to install it.
To set up the C build environment on Linux,请按照以下步骤操作。
- 打开一个终端。
- On Red Hat and Fedora, run:
sudo yum groupinstall 'Development Tools' - On Debian and Ubuntu, 跑:
sudo apt-get update sudo apt-get install build-essential manpages-dev - 验证安装:
gcc --version
如何在 macOS
On macOS, the GCC-compatible toolchain ships through Apple’s Command Line Tools for Xcode.
- 打开一个终端并运行:
xcode-select --installA dialogue prompts you to install the Command Line Tools. Click 安装 and accept the licence.
- Alternatively, sign in at https://developer.apple.com/download/all/ with your Apple developer ID, download the latest Command Line Tools for Xcode
.dmg, and run the installer. Keep the wizard defaults. - Open a terminal and verify the install:
gcc -v
Verify Your GCC Installation
Regardless of the operating system, a quick sanity check confirms that the compiler is on the PATH:
gcc --version
You should see output similar to gcc (GCC) 13.2.0 followed by the licence notice. Compile a one-line “hello, world” to test the full pipeline:
// hello.c
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
Build and run with:
gcc hello.c -o hello
./hello
Troubleshooting Common GCC Install Issues
The problems below cover most install-time complaints:
- “gcc is not recognized” on Windows: add the MinGW
binfolder to your PATH environment variable, then restart the terminal. - Code::Blocks does not detect the compiler: open Settings → Compiler → Toolchain executables and point the compiler installation directory at your MinGW root (e.g.,
C:\MinGW). - Linux says “command not found”: the package may have installed as
gcc-12orgcc-13。 跑which gccand create a symlink, or call the versioned binary directly. - macOS reports “clang” instead of GCC: Xcode aliases clang as
gcc. If you need genuine GCC, install it through Homebrew withbrew install gcc并打电话gcc-13. - Missing headers (e.g., stdio.h): 重新安装
build-essentialon Linux or the Xcode Command Line Tools on macOS to restore the standard library headers.
Other Popular C Compilers
If GCC does not suit your environment, several alternatives compile and run C reliably:
- 铛 — LLVM-based compiler with fast builds and excellent diagnostics. Default on macOS.
- 明GW-w64 — modern fork of MinGW with up-to-date GCC binaries for Windows.
- Portable C compiler (pcc) — lightweight, BSD-licensed compiler.
- Turbo C. — classic compiler still common in academic settings.
- Microsoft 视觉 C++ (MSVC) - Microsoft’s compiler shipped with Visual Studio; compiles C with the
/TC开关。









