The error message "exec: gcc: executable file not found in %path%" is a common issue faced by developers while trying to compile C/C++ programs using the GNU Compiler Collection (GCC). This error usually occurs when the GCC executable is not properly installed or its location is not added to the system's environment variable called PATH
. In this comprehensive guide, we will walk you through the steps to fix this error and get your compilations up and running.
Table of Contents
Prerequisites
Before attempting to fix the error, ensure that you have the following installed on your system:
- GCC: Download and install the appropriate version of GCC for your operating system.
- A text editor or IDE: You can use any text editor or IDE of your choice for writing and editing your C/C++ code.
Verify GCC Installation
First, verify that GCC is installed on your system by running the following command in your terminal or command prompt:
gcc --version
If the installation was successful, you should see the GCC version details. If not, you might need to reinstall GCC or add its location to your system's PATH variable.
Adding GCC to PATH
If you've verified that GCC is installed on your system but you're still encountering the error, it's likely that the location of the GCC executable is not added to the PATH variable. Follow the steps below for your operating system to add GCC to the PATH:
Windows
Locate the GCC installation directory, typically found in C:\Program Files (x86)\mingw-w64
.
Open the mingw-w64
folder and navigate to the bin
directory. Copy the full path of this directory.
Right-click on "This PC" or "My Computer" and select "Properties".
Click on "Advanced system settings" and then click on the "Environment Variables" button.
In the "System variables" section, scroll down and find the "Path" variable. Select it and click on "Edit".
Click on "New" and paste the copied path of the bin
directory. Click "OK" to save the changes.
- Restart your terminal or command prompt and try running the
gcc --version
command again. The error should be resolved.
macOS and Linux
Open a terminal window and run the following command to open the bash_profile
or bashrc
file in a text editor:
- For macOS:
nano ~/.bash_profile
- For Linux:
nano ~/.bashrc
Add the following line to the file, replacing /path/to/gcc/bin
with the actual path to the GCC bin
directory:
export PATH=$PATH:/path/to/gcc/bin
Save the changes and exit the text editor.
- Restart your terminal and try running the
gcc --version
command again. The error should be resolved.
FAQs
1. How do I find the path to the GCC bin
directory on my system?
For Windows, the path is usually C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin
. Replace i686-8.1.0-posix-dwarf-rt_v6-rev0
with the appropriate folder name corresponding to your installed GCC version. For macOS and Linux, the path is typically /usr/local/bin
. You can also run the command which gcc
to find the path on macOS and Linux.
2. How do I verify if the GCC bin
directory is already included in the PATH variable?
For Windows, follow the steps mentioned in the Adding GCC to PATH (Windows) section and check if the path exists in the list. For macOS and Linux, run the following command in the terminal:
echo $PATH
Check if the path to the GCC bin
directory is included in the output.
3. What other issues can cause the "exec: gcc: executable file not found in %path%" error?
Apart from the GCC executable not being in the PATH, other issues that can cause this error include:
- Corrupted or incomplete installation of GCC.
- Conflicting installations of GCC or other C/C++ compilers.
4. How can I reinstall GCC on my system?
Follow the appropriate installation guide for your operating system to reinstall GCC. Make sure to uninstall any previous installations before proceeding.
5. Can I have multiple versions of GCC installed on my system?
Yes, you can have multiple versions of GCC installed on your system. However, you need to ensure that the desired version is the one included in the PATH variable. You can also use the update-alternatives
command on Linux to manage multiple installations of GCC.