Linux gcc-missHigh

Linux 'gcc not found' Error: Causes and Quick Fixes

This article explains why the system cannot find the GCC compiler and offers several solutions: from simple installation via package manager to manual environment variable configuration.

Updated at February 15, 2026
5-10 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04/22.04Debian 11/12CentOS 7/8Fedora 35+All Linux-based distributions

What the 'gcc: command not found' Error Means

The error gcc: command not found (or bash: gcc: command not found) appears in the Linux terminal when the system cannot find the GCC compiler executable file in the directories specified in the PATH environment variable. This occurs when attempting to compile a C/C++ program or run a script that requires GCC.

The full error text usually looks like this:

bash: gcc: command not found

Or simply:

gcc: command not found

The error blocks code compilation and indicates that the compiler is missing or misconfigured.

Causes

  1. GCC is not installed. In a fresh Linux installation (especially minimal ones), the compiler is often absent by default.
  2. GCC is installed, but not in a standard directory. For example, if you compiled GCC from source and installed it to /opt/gcc, but that folder is not added to PATH.
  3. The PATH variable is corrupted or changed. The system only searches for executable files in the directories listed in PATH. If the path to GCC is removed from this variable, the command is not found.
  4. GCC is installed only for another user. For example, installed via sudo for root, but not accessible to a regular user (rare, but possible with non-standard configuration).
  5. Symbolic links to GCC are missing. Sometimes GCC is installed in a subdirectory (e.g., /usr/lib/gcc/x86_64-linux-gnu/11/), and a symbolic link gcc -> /usr/lib/gcc/.../gcc should exist in /usr/bin. If the link is broken or removed, the command is not found.

Solutions

Method 1: Installing GCC via Package Manager

The simplest and most reliable method is to install GCC from your distribution's official repositories. This ensures correct paths and dependencies.

For Ubuntu/Debian and derivatives:

sudo apt update
sudo apt install build-essential

The build-essential package includes GCC, G++, make, libc6-dev, and other compilation tools.

For CentOS/RHEL 7:

sudo yum install gcc

For CentOS/RHEL 8 / Fedora / AlmaLinux / Rocky Linux:

sudo dnf install gcc

For Arch Linux:

sudo pacman -S gcc

After installation, verify:

gcc --version

If you see a version number, the issue is resolved.

Method 2: Adding the GCC Path to the PATH Variable

If GCC is already installed (e.g., you manually installed it to /usr/local/gcc), but the system doesn't find it, you need to add the directory containing the executable to PATH.

  1. Find where gcc is located:
    which gcc
    

    If the command outputs nothing, search in typical locations:
    sudo find / -name gcc 2>/dev/null | head -20
    

    GCC is usually in /usr/bin/gcc, /usr/local/bin/gcc, or /opt/gcc/bin/gcc.
  2. Add the path to PATH. Open the ~/.bashrc file (for bash) or ~/.zshrc (for zsh) in a text editor:
    nano ~/.bashrc
    

    At the end of the file, add a line (replace /path/to/gcc with the actual path, e.g., /usr/local/bin):
    export PATH=$PATH:/usr/local/bin
    

    Save and close the editor.
  3. Apply the changes:
    source ~/.bashrc
    

    Or open a new terminal window.
  4. Verify:
    echo $PATH
    gcc --version
    

If GCC is installed but the executable file resides in a deep subdirectory (e.g., /opt/gcc/bin/x86_64-pc-linux-gnu/gcc), you can create a symbolic link in /usr/local/bin:

sudo ln -s /opt/gcc/bin/x86_64-pc-linux-gnu/gcc /usr/local/bin/gcc

Then verify with gcc --version.

Method 4: Checking and Fixing the PATH Variable

If you or other programs modified PATH and broke it, restore the standard value. Typically, PATH includes /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.

  1. View the current PATH:
    echo $PATH
    
  2. If paths are missing, add them temporarily:
    export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
    
  3. To make changes permanent, edit ~/.bashrc (as in Method 2) and add the full PATH line there.

Method 5: Reinstalling GCC (if the Package is Corrupted)

If GCC was installed via a package manager but functions incorrectly, reinstall it:

For Ubuntu/Debian:

sudo apt remove --purge gcc
sudo apt install build-essential

For CentOS/Fedora:

sudo dnf remove gcc
sudo dnf install gcc

Prevention

  • Install GCC from official repositories — this ensures correct paths and automatic updates.
  • Do not remove standard directories from PATH — especially /usr/bin and /bin.
  • Check PATH after changes — if you edited ~/.bashrc or system files, ensure the syntax is correct.
  • Use virtual environments for C/C++ projects (e.g., via conda or docker) to isolate dependencies.
  • Regularly update your system — this includes updating compiler packages:
    sudo apt update && sudo apt upgrade  # for Debian/Ubuntu
    sudo dnf upgrade                    # for Fedora/CentOS 8+
    

After completing these steps, the gcc: command not found error should disappear, and you will be able to compile C and C++ programs on your Linux system.

F.A.Q.

Why does the 'gcc: command not found' error occur?
How to check if GCC is installed?
Can I use GCC without installing it?
What to do if GCC is installed but the error persists?

Hints

Check if GCC is installed
Install GCC via package manager
Add GCC path to PATH variable
Reload the shell
Test GCC functionality

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