How to fix the error “gcc no such file or directory”

The GCC (GNU Compiler Collection) is a standard compiler used in Linux to compile C/C++ programs. With the help of GCC, we can compile the program straight in the terminal. Often times when dealing with GCC, an error can be prompted with the statement “unable to execute gcc no such file or directory”.

This article provides possible reasons that invoke the problem with the statement “gcc no such file or directory”. Furthermore, we have demonstrated the solution as well.

Resolve the problem “gcc no such file or directory”?

There are some diverse reasons that can invoke this error. In this section reasons for the problem will be explained as well as the methods of how to fix it.

Reason: Missing GCC

The first most obvious reason is that your system does not have the gcc installed on it. You can verify the installation of GCC using the following command in your Linux terminal:

$ gcc

If this command returns the following error, this means that gcc is not installed on your system:

Solution: Install the GCC

To fix the issue you simply need to install the GNU compiler collection onto your system. Let’s elaborate on how GCC will be installed. There are two distinct methods through which this can be achieved.

Method 1: Using apt

The simplest way is to use the apt installer to install GCC. Simply run the following command:

$ sudo apt install gcc

The snippet above shows that gcc will successfully be installed using the apt installer.

Method 2: Using build essentials

The second method is to install build-essentials onto your system which will also include the gcc. Run the commands below into the terminal to execute it:

$ sudo apt update
$ sudo apt install build-essential

Once you have installed gcc on your system using either of the methods, it can be double-checked using the command mentioned below:

$ gcc -version

This proves that GCC has now been installed. The process should remove the “gcc no such file or directory” error during an attempt to compile any files.

Conclusion

The “gcc no such file or directory” issue occurs when the gcc is not installed in your system. To install GCC, you can use either the command “sudo apt install gcc” or the alternate command “sudo apt install build-essential” command. Here, you have learned the reason for the error “gcc no such file or directory” and the two methods to fix this error.