-3

Whenever I set MingW64 PATH environment variable it is automatically removed.

I also tried using cmd to set the PATH

setx path "%path%;C:\msys64\mingw64\bin"

But even after this command if I try

g++ --version

I still gets this error

'g++' is not recognized as an internal or external command, operable program or batch file.

I am using Windows 10

What should I do?

Thanks in advance

Compo
  • 36,585
  • 5
  • 27
  • 39
xspd3000
  • 83
  • 1
  • 1
  • 4
  • 3
    [setx](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/setx) doesn't set environment variables in the current terminal – Alan Birtles Dec 26 '21 at 09:24
  • 2
    How exactly do you add it to the path? If you do it from the CMD, the change only affects the current terminal session, and is undone after you close it. – HolyBlackCat Dec 26 '21 at 09:24
  • I added it with settings – xspd3000 Dec 27 '21 at 11:00

1 Answers1

1

To add a new location to your User Environment Path value string, (or create a new value if one did not already exist), for use in future cmd.exe sessions, but not in the current one, you could use something like this:

@Echo Off

Rem Please note: The Path variable stringtype is REG_EXPAND_SZ.
Rem   This means it will auto expand contained variables within the location string.
Rem   It is therefore recommended that you include those possible.
Rem   But please be aware, when you include them below, double all percent characters. 
Rem Enter your new User Path string entry here:
Set "NewString=%%SystemDrive%%\msys64\mingw64\bin"

Set "Reg=%SystemRoot%\System32\reg.exe"
Set "Key=HKCU\Environment"
Set "StX=%SystemRoot%\System32\setx.exe"

%Reg% Query "%Key%" /V Path 1>NUL 2>&1 && (For /F "EOL=H Tokens=2,*" %%G In ('
     %Reg% Query %Key% /V Path 2^>NUL') Do %StX% Path "%NewString%;%%H" 1>NUL
    ) || %Stx% Path "%NewString%;" 1>NUL

For the current cmd.exe session only, you'd do it more like this:

@Echo Off
Path "C:\msys64\mingw64\bin;%Path%"

You could therefore, if you wish, append this as the next line in the upper script, to allow its use in the current instance, and for all future ones:

Path "%NewString%;%Path%"
Compo
  • 36,585
  • 5
  • 27
  • 39