The Mingw binary installation instructions (such as these) tells me to change the PATH environment variable in Windows, in order to use the gcc/g etc commands anywhere. This might also be necessary for some programming IDE to find the compiler. Failing to do so yields errors such as this:
'gcc' is not recognized as an internal or external command, operable program or batch file.
How do I do this specifically in newer versions of Windows (10/11) and which path should I use?
CodePudding user response:
- Right-click "My Computer"/"This PC" from Windows explorer and pick properties. Alternatively Windows key X and click "System". An "About" window appears.
- Scroll down to "Advanced system settings" and click on it.
- Click on the "Environment Variables" button.
- Select "Path" in the window that appears and click the edit button.
- Click on "Edit text" (not on "Edit"!).
- Before modifying anything, I strongly recommend to copy the text there and save it in a text file for backup, so that you can restore the
PATHin case of mistakes. - Write a semicolon
;at the end of the text there unless already present. Then after the semicolon add the full path to your Mingw installation'sbinfolder. For example;c:\mingw_w64\bin. - Important: if you installed Mingw under for example
C:\program files\mingw_w64, then the path must be;C:\Program Files\mingw-w64\bin;without any surrounding" ... ". If using the "Edit" command available in this window, then the" ... "will get added and this may break the gcc path from working. (It just happened to me and that's the reason why I decided to write this Q&A.) - Click OK for each open window.
- Reboot Windows.
Now you should be able to type gcc from the command line or use it from your programming IDE.
CodePudding user response:
Alternatively, for CLI users:
- Open
cmd. - Type
PATH. - Add the absolute path to the
binfolder to it. - Place a semi-colon at the end.
- Press enter.
- Reboot.
And you're done.
Edit: For the full path to the bin folder:
cdyour way toMingwinstallation'sbinfolder, or alternatively, presswindows key e.- Open
mingw->bin. - Copy the full path present in the search bar.
As @Lundin said, you should first make a copy of the original PATH and save it, just in case something goes wrong.
