gcc is not recognized as an internal or external command

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
5 min

banner

# Table of Contents

  1. gcc is not recognized as an internal or external command
  2. Install gcc (GNU Compiler Collection) on Windows
  3. Add the path to the MinGW Binary to your PATH environment variable
  4. Using Chocolatey to set up GCC instead

# gcc is not recognized as an internal or external command

The error "'gcc' is not recognized as an internal or external command, operable program or batch file" occurs for 2 main reasons:

  • gcc (GNU Compiler Collection) is not installed on your machine.
  • The path to the MinGW binary is not added to your PATH environment variable.

gcc is not recognized as an internal or external command

Depending on if you run the gcc command in CMD or PowerShell, you will get one of the following two errors:

  • 'gcc' is not recognized as an internal or external command, operable program or batch file.
  • The term 'gcc' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

# Install gcc (GNU Compiler Collection) on Windows

The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Ada, Go, and D.

First, make sure that you have gcc installed:

  1. Download the MinGW setup.exe file by clicking on the following link.

Once you click on the link, wait a few seconds and the download will start automatically.

  1. Start the mingw-get-setup.exe file.

  2. If you get shown a screen that "The app you're trying to install isn't a Microsoft verified app", click on Install anyway to proceed.

click install anyway

  1. Click on Install on the next screen.

click install

  1. Leave the default installation directory selected and all other defaults and click on Continue.

The default installation directory should be C:\MinGW as shown in the screenshot.

leave default installation directory selected

  1. On the next screen choose Continue.

If you already have MinGW installed, you will get a notification as shown in the screenshot.

If you do, click on Run now instead.

select continue on next screen

# Add the path to the MinGW Binary to your PATH environment variable

The next step is to add the path to the MinGW binary to your PATH environment variable:

  1. Click on the Search bar and type "environment variables".
  2. Click on "Edit the system environment variables".

edit system environment variables

  1. Click on the "Environment Variables" button.

click environment variables

  1. Under System variables find the PATH environment variable and double-click it or select it and click on the Edit button.

select path and click edit

  1. Click on the New button at the top left corner of the Edit environment variable window.

Add the following path: C:\MinGW\bin.

shell
C:\MinGW\bin

add path to mingw binary to path environment variable

If you changed the path during the MinGW installation process, make sure to specify the correct path to the MinGW binary.

If you open the C:\MinGW\bin directory, you will see that it contains the GCC executable file (gcc.exe).

path to mingw binary contains gcc exe

This is the file that is run when you issue gcc commands from your terminal.

When you add the PATH to the MinGW bin folder to your PATH environment variable, your terminal is able to find the gcc.exe file.

  1. Click on OK 3 times to apply the changes.

  2. Close all terminal sessions for the changes to be applied.

Note: it's very important to close and reopen CMD for the PATH environment variable to get updated.

In a new CMD session, issue the gcc --version or gcc -v command to verify that the error has been resolved.

CMD
gcc --version # Or the following gcc -v

issue gcc version command

As shown in the screenshot the gcc command is now available.

Once you've added the path to the MinGW bin folder to your System PATH environment variable the issue should be resolved.

If the error persists, try to issue the following command in CMD.

CMD
set Path=C:\MinGW\bin;%PATH%

add path to mingw binary to path using cmd

The command adds the path to the MinGW bin folder to your PATH environment variable.

Try to issue the gcc -version command.

CMD
gcc --version # or gcc -v

issue gcc version command

You should also be able to run gcc commands by specifying the complete path \mingw\bin\gcc.

CMD
\mingw\bin\gcc --version # or \mingw\bin\gcc -v

If the error persists, verify that your MinGW installation is located in C:\.

If MinGW is installed in a different folder, you have to make sure to correct the path to the MinGW\bin folder.

# Using Chocolatey to set up GCC instead

If the error persists, install MinGW using Chocolatey.

If you already have Chocolatey installed:

  1. Click on the Search bar and type PowerShell.

  2. Right-click on the PowerShell application and click "Run as administrator".

run powershell as administrator

  1. Run the following command to install MinGW.
shell
choco install mingw -y

install mingw using chocolatey

If you don't have Chocolatey installed, you have to install it first.

To install Chocolatey:

  1. Open PowerShell as an administrator.

run powershell as administrator

  1. Run the following command.
PowerShell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

windows install chocolatey

  1. Wait for the command to complete.
  2. Type choco to make sure Chocolatey is installed.

windows verify chocolatey installed

Now that you have Chocolatey installed, run the following command to install mingw.

shell
choco install mingw -y

Note that your shell should still be run using elevated permissions.

install mingw using chocolatey

Close your active Command Prompt sessions and start a new session.

Try to issue the gcc -version command.

CMD
gcc --version # Or the following gcc -v

issue gcc version command

Chocolatey will automatically add the path to the MinGW bin folder to your PATH after you install MinGW.

# Conclusion

To solve the error "'gcc' is not recognized as an internal or external command, operable program or batch file", make sure:

  1. You have MinGW installed on your Windows machine.
  2. You have added the path to the MinGW bin folder to your system's PATH environment variable.
  3. Alternatively, you can install MinGW using Chocolatey, which automatically adds the path for you.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.