How to Add Gcc to Path Linux
The quickest way to fix how to add gcc to path linux is to find the directory that contains the gcc binary, then add that directory to your PATH in your shell configuration file. In many Linux setups, gcc is already available in /usr/bin, so you may not need to add anything at all if the compiler is installed correctly.
Quick answer
If gcc is installed but your terminal says command not found, add the directory that contains gcc to PATH. For a temporary fix, run a command like this:
export PATH="/path/to/gcc/bin:$PATH"For a permanent fix, put that line in the right shell startup file, such as ~/.bashrc, ~/.zshrc, or ~/.profile, depending on the shell you use.
Find where gcc is installed
Before changing PATH, confirm where gcc lives on your system. The goal is to add the directory that contains the executable, not the gcc file itself.
Try one of these commands:
which gcc
command -v gcc
whereis gccIf gcc is installed in a standard system location, you may see something like /usr/bin/gcc. If you built GCC yourself or installed a custom toolchain, the path may look more like /usr/local/bin/gcc or a versioned directory under your home folder.
What PATH actually does
PATH is an environment variable that tells your shell where to look for executable commands. When you type gcc, the shell checks each directory in PATH until it finds the program. If gcc is not in one of those directories, the shell cannot run it.
Add gcc to PATH for the current session
If you want a quick, temporary fix, you can update PATH only for the current terminal session. This is useful for testing or for one-time work.
- Find the directory that contains gcc, for example
/usr/local/gcc/bin. - Run the export command:
export PATH="/usr/local/gcc/bin:$PATH"This places the gcc directory at the front of PATH, so your shell finds that version first. If gcc is in /usr/bin, you usually do not need to add it because most Linux systems already include that directory in PATH.
Make the PATH change permanent
To keep the change after you close the terminal, add the export line to the correct shell startup file. Which file you use depends on your shell and whether the shell is interactive or login-based.
Bash vs Zsh configuration files
Use the file that matches your shell:
- Bash: usually
~/.bashrcfor interactive shells, or~/.profilefor login shells. - Zsh: usually
~/.zshrc. - Other shells: check the shell’s documentation for the recommended startup file.
To edit the file, open it with your preferred text editor. For example:
nano ~/.bashrcThen add a line like this near the end:
export PATH="/usr/local/gcc/bin:$PATH"Save the file and reload it with:
source ~/.bashrcIf you edited ~/.zshrc, use:
source ~/.zshrcYou can also open a new terminal session instead of sourcing the file.
If gcc is already in /usr/bin
If your gcc binary is located in /usr/bin, do not add that path unless your system is unusually configured. On most Linux distributions, /usr/bin is already in PATH by default. If gcc still is not found, the problem is more likely that GCC is not installed or that your shell configuration is overriding PATH.
Verify gcc works
After updating PATH, check that the shell can find gcc and that the compiler runs correctly.
command -v gcc
gcc --versionIf the first command prints a path and the second command shows a version number, your setup is working.
If it still fails, the problem is usually one of these:
- The wrong directory was added to PATH.
- The PATH change was added to the wrong shell file.
- The shell session was not restarted or reloaded.
- GCC is not installed at all.
Troubleshooting common issues
When gcc is still not recognized after editing PATH, the issue is usually easy to narrow down.
Multiple GCC versions
If you have more than one GCC installation, the order of directories in PATH matters. The shell uses the first match it finds. You can check which compiler is being used with:
which gcc
command -v gccIf the wrong version appears first, move the preferred gcc directory earlier in PATH. For example, placing /opt/gcc-13/bin before /usr/bin makes the shell prefer that version.
Permission or install path problems
If gcc is installed in a custom location, make sure the binary is actually executable. You can inspect it with:
ls -l /path/to/gcc/bin/gccIf the file exists but is not executable, PATH changes will not help. You may need to reinstall GCC or fix the installation permissions.
Login shell versus non-login shell
Some terminals read different startup files depending on whether they launch a login shell. If your change works in one terminal but not another, add the export line to the file your shell actually reads. For Bash, ~/.bashrc and ~/.profile are the most common files to check.
PATH was overwritten
Sometimes a startup file contains a line that resets PATH instead of extending it. Look for lines like PATH=... that remove system directories. When possible, append to PATH using:
export PATH="/your/gcc/bin:$PATH"This keeps the existing entries and avoids breaking other commands.
Should you add /usr/bin to PATH?
Usually no. Most Linux distributions already include /usr/bin in PATH. If gcc is installed there and still not found, adding /usr/bin is not the real fix. Instead, check whether your shell configuration is broken or whether gcc is missing from the system.
Practical examples
Here are a few common cases:
- System package install: gcc is in
/usr/bin, so no PATH change is usually needed. - Custom local install: gcc is in
/usr/local/gcc/bin, so add that directory to PATH. - User-space toolchain: gcc is installed under your home directory, so add that custom bin folder to PATH in your shell startup file.
Example permanent entry for Bash:
export PATH="$HOME/toolchains/gcc/bin:$PATH"Best practice
If you are using a package-managed Linux installation, install GCC through your distribution’s package manager first, then verify the command works before editing PATH. Use PATH changes mainly for custom installs, multiple versions, or development toolchains outside the standard system locations.
Frequently Asked Questions About how to add gcc to path linux
How do I add gcc to PATH in Linux?
Find the directory that contains the gcc binary, then add that directory to PATH with an export command. Put the same line in your shell startup file if you want the change to persist.
Why is gcc command not found on Linux?
Either GCC is not installed, or its bin directory is not in PATH. It can also happen if your shell configuration resets PATH or you are using the wrong startup file.
How do I permanently set PATH for gcc?
Add export PATH="/path/to/gcc/bin:$PATH" to ~/.bashrc, ~/.zshrc, or ~/.profile, depending on your shell. Then reload the file with source or open a new terminal.
How do I check where gcc is installed?
Use which gcc, command -v gcc, or whereis gcc. These commands help you locate the executable and confirm whether the shell can already see it.
Do I need to add /usr/bin to PATH for gcc?
Usually no. Most Linux systems already include /usr/bin in PATH. If gcc is there but not found, the issue is usually installation or shell configuration, not the absence of /usr/bin in PATH.
What is the difference between temporary and permanent PATH changes?
A temporary PATH change works only for the current terminal session. A permanent change is saved in a shell startup file and applies every time you open a new terminal.
Conclusion
To add gcc to PATH on Linux, first locate the directory that contains the gcc executable, then export that directory into PATH. Use a temporary export for quick testing, and save the line in the correct shell startup file for a permanent fix. In many cases, gcc is already in /usr/bin, so the real issue is missing installation or the wrong shell configuration rather than PATH itself.
