If you are a developer and trying to compile your C/C++ program in the command prompt, then this article will help you to install gcc compiler and g++ compiler on your Windows 10 computer in order to compile your code. If these compilers are not installed, you will get the error “gcc is not recognized as an internal or external command“.
Before we proceed with the installation steps, you must know about these tools.
- Minimalist GNU for Windows (MinGW): It is a development environment for Windows applications.
- gcc compiler: Use this compiler to compile C programs.
- g++ compiler: Use this compiler to compile C++ programs.
gcc and g++ compiler along with other compilers come together as a package when you install the MinGW tool. So, you are required to download and install the MinGW tool on your development environment.
Here is a step-by-step guide.
Step 1: Download MinGW tool
You can download the installable from MinGW official website or from any other trusted source.
On the official website, click on the Downloads tab on the top side and go to List of Releases. Under the Download List section, look for the Windows download button as shown below and download the setup file.
The mingw-get-setup.exe file gets downloaded to your computer in the downloads folder.
Step 2: Steps to install MinGW
- Right-click on the mingw-get-setup.exe file and run as administrator.
- In the MinGW Installation Manager Setup Tool window, click on Install.
- By default, the installation directory is set as C:\MinGW. You can change the installation directory by clicking on the Change button and selecting a different folder.
- Click on the Continue button to start the installation.
- Once the installation is complete, click the Continue button to close MinGW Installation Manager Setup Tool.
Step 3: Install packages in MinGW / Install gcc compiler
Once you install MinGW, open MinGW Installation Manager from the Windows start menu that contains the list of packages you can install.
Select the packages you want to install and right-click and choose Mark for Installation. Make sure to mark all GNU C compilers as shown below.
Note: After installation, if you want to remove, upgrade or reinstall certain packages, then you can use MinGW Installation Manager and choose respective option by right-clicking on the package.
Once you mark all packages for installation click on Installation menu and select Apply Changes.
In the Schedule of Pending Actions window, click on Apply button. It starts installing marked packages on your local environment.
Step 4: Set up the environment variable for MinGW
Once the MinGW setup is complete and the gcc and g++ compiler packages are installed, you must set the PATH variable for your computer.
- Go to Control Panel → System and Security → System or right-click on This PC → Properties.
- Click on Advanced system settings. It opens System Properties dialog box.
- In the System Properties window, under the Advanced tab, click on the “Environment Variables...” button to open the environment variables window.
- Under the System variables section, edit the path variable and append gcc compiler path up to the bin folder.
Note: The bin folder contains executable files of the compiler.
Step 5: Test installation of gcc and g++ compiler
To test if the gcc compiler or the g++ compiler is installed correctly, open a command prompt and type the following command.
For gcc compiler:
For g++ compiler:
If these commands return the version of the compiler, then it means you have installed gcc and g++ compilers correctly.
If you are getting an error message “gcc is not recognized as an internal or external command” then click on the below link to resolve the error.
These are all the steps you need to follow in order to install gcc compiler and g++ compiler on your computer and execute your C/C++ program in the command prompt. If you have any questions or issues, do let us know in the comments section.