Linux gcc: commandMedium

Fix gcc: command not found in Linux in 5 Minutes

The `gcc: command not found` error occurs when trying to compile a C/C++ program without the compiler installed. Learn how to quickly check for the package and install it on popular Linux distributions.

Updated at April 6, 2026
5-10 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04+Debian 11+Fedora 36+Arch Linux

What the "gcc: command not found" Error Means

The bash: gcc: command not found message (or simply gcc: command not found in other shells) appears when you try to run the gcc command to compile C or C++ code, but the terminal cannot locate the executable in the system's standard directories. This typically happens when running gcc for the first time after a fresh Linux installation or when working in a minimal environment (Docker, WSL, server builds). The system won't crash, but the build process will terminate immediately.

Common Causes

  • The GCC compiler is not installed. Minimal Linux images often exclude development tools to save space.
  • Missing build dependencies. The gcc package is installed, but dependencies like make, g++, or header libraries are missing, which may have caused the package manager to roll back the installation.
  • Corrupted PATH variable. The compiler binary physically exists at /usr/bin/gcc, but the shell is searching for it in other directories.
  • Terminal session not refreshed. The installation completed successfully, but the current shell has cached the old paths and cannot see the new binaries.

How to Fix It

Method 1: Install via Meta-Package (Ubuntu/Debian)

This is the most reliable method for Debian-based systems. Instead of installing the standalone gcc package, we will install build-essential, which includes everything needed for compilation.

  1. Open a terminal and update the repository cache:
    sudo apt update
    
  2. Install the package:
    sudo apt install build-essential
    
  3. Confirm the action by pressing Y and wait for the download and installation to complete.

💡 Tip: If you are working with C++, also verify that g++ is installed. On Ubuntu, it is included in build-essential, but older Debian versions may require sudo apt install g++.

Method 2: Using Native Package Managers (Fedora/Arch)

Other distributions use their own package groups. The installation logic is identical; only the package manager commands differ.

  • Fedora/RHEL/CentOS Stream:
    sudo dnf check-update
    sudo dnf groupinstall "Development Tools"
    
  • Arch Linux/Manjaro:
    sudo pacman -Syu base-devel
    

After running these commands, the system will automatically resolve dependencies and install GCC, make, pkg-config, and other auxiliary utilities.

Method 3: Fixing the PATH Variable

If the installation completed without errors but the terminal still cannot find gcc, verify the binary's location and ensure it is accessible to your shell.

  1. Locate the actual file path:
    find /usr -name gcc -type f 2>/dev/null
    
    Expected output: /usr/bin/gcc or /usr/local/bin/gcc.
  2. If the file is found, add its directory to your environment variable. Open your shell configuration file:
    nano ~/.bashrc
    
  3. Append the following line to the end of the file:
    export PATH="/usr/bin:$PATH"
    
  4. Save the changes (Ctrl+O, Enter, Ctrl+X) and apply them without restarting:
    source ~/.bashrc
    

⚠️ Important: Do not modify system-wide paths in /etc/environment unless you fully understand the consequences. Editing ~/.bashrc or ~/.zshrc is safe and only affects your user account.

Prevention

To prevent this error from recurring during system updates or when deploying new projects, follow these best practices. Always use package managers to install development tools—never manually copy binaries into /usr/local/bin. If you are working with containers or CI/CD pipelines, explicitly include the installation of build-essential or gcc in your Dockerfile during the image build stage. Periodically verify package integrity using apt --fix-broken install or dnf check to avoid scenarios where an interrupted update leaves dependencies in a broken state.

F.A.Q.

Why does the terminal still say gcc is not found after installation?
What is the difference between `build-essential` and the standalone `gcc` package?
Can I use clang instead of gcc?
Do I need to reboot my computer after installing the compiler?

Hints

Check if the compiler is installed
Update package lists
Install the compiler and utilities
Verify the installation

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community