如何在……上安装 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.

  • 📥 选择正确的 Windows 捆: 选择 Code::Blocks MinGW installer (e.g., codeblocks-17.12mingw-setup.exe) so GCC, GDB, and the IDE are configured in one step.
  • 🐧 Use the Linux package manager: On Debian/Ubuntu 运行 sudo apt-get install build-essential, on Fedora/Red Hat run yum groupinstall 'Development Tools'.
  • 🍎 安装 Xcode Command Line Tools on macOS: 一个单一的 xcode-select --install command pulls in Apple’s clang plus the GCC-compatible toolchain.
  • Verify with gcc –version: 安装后,运行 gcc --version in a terminal to confirm the compiler is on the PATH and ready to compile C programs.
  • 🤖 Use AI to troubleshoot: AI assistants explain installer errors, PATH issues, and missing-header warnings, helping beginners reach a working build on the first attempt.

How to Download and Install GCC Compiler

什么是海合会?

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.

Code::Blocks Binary Release page

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::阻止源文件。

选择 Code::Blocks installer with GCC

步骤3)开始安装

Run the downloaded installer and accept the default options. This straightforward process sets up the GCC compiler on your Windows 系统。

开始 Code::Blocks installation

Step 4) Accept the licence agreement

Accept the licence agreement to continue.

Accept licence agreement

Step 5) Keep the default component selection

Leave the component selection at its default and click 下一篇.

Keep default components

Step 6) Choose the installation path

Change the installation folder if you wish, then click 下一篇.

Choose installation path

步骤 7) 启动 Code::积木

找到 Code::Blocks shortcut on your desktop or Start menu and double-click it.

Code::Blocks icon

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.

Code::Blocks detects compiler

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.

Code::Blocks IDE home screen

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,请按照以下步骤操作。

  1. 打开一个终端。
  2. On Red Hat and Fedora, run:
    sudo yum groupinstall 'Development Tools'
  3. On Debian and Ubuntu, 跑:
    sudo apt-get update
    sudo apt-get install build-essential manpages-dev
  4. 验证安装:
    gcc --version

如何在 macOS

On macOS, the GCC-compatible toolchain ships through Apple’s Command Line Tools for Xcode.

  1. 打开一个终端并运行:
    xcode-select --install

    A dialogue prompts you to install the Command Line Tools. Click 安装 and accept the licence.

  2. 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.
  3. 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 bin folder 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-12 or gcc-13。 跑 which gcc and 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 with brew install gcc 并打电话 gcc-13.
  • Missing headers (e.g., stdio.h): 重新安装 build-essential on 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 开关。

常见问题

GCC stands for the GNU Compiler Collection. It is a free, open-source compiler suite maintained by the Free Software Foundation that supports C, C++,Objective-C, Fortran, Ada, and Go.

GCC is the compiler itself. MinGW (Minimalist GNU for Windows) is a port that bundles GCC with the Windows libraries needed to build native executables, making it the most common GCC distribution on Windows.

Open a terminal or Command Prompt and run gcc --version. If GCC is on the PATH the command prints the installed version. Otherwise the shell reports that the command is not found.

Yes. GCC is distributed under the GNU GPL with a runtime library exception that lets you compile and ship proprietary software. You can use GCC in commercial projects without paying any licence fee.

No. GCC runs entirely from the command line. IDEs such as Code::Blocks, VS Code 或 CLion add convenience features — syntax highlighting, debugging, and project templates — but the compiler works without them.

The MinGW bin folder is missing from the PATH. Add it through the Windows Environment Variables dialogue, reopen the terminal, and the gcc command becomes available globally.

AI assistants translate installer errors and PATH issues into plain-English fixes, suggest the right package manager command for your distribution, and explain GCC warnings so beginners learn while debugging.

Yes. AI code assistants generate a “hello, world” program, plus the exact gcc hello.c -o hello command to compile it. They also explain what each line does so beginners review before running.

总结一下这篇文章: