In Windows, the setx command allows storing environment variables in the Windows registry on a per-user or system basis. A problem arises when it is desired to remove such variables entirely. Unlike older versions of Windows, setting a blank value does not work in Windows 10.
Assume one previously set the environment variable
CC to the
Intel C compiler
setx CC icc
Now the problem is, you’d like the system to fall back to using whatever default C compiler is on the Windows system. The existing variable is visible in PowerShell via:
But trying to remove the variable with PowerShell command
is only effective for this PowerShell session. The old value of
CC comes back upon opening a new PowerShell.
Permanently remove setx variable
To permanently remove the variable, we must remove it from where it’s stored in the Windows registry.
For this example of wanting to delete enviornment variable
CC, do from PowerShell:
reg delete "HKCU\Environment" /v CC
Optionally, confirm deletion with PowerShell: