Environment Variables - alarwasyi98/dotfiles-win GitHub Wiki

Environment variables are key-value pairs used by Windows and applications to control behavior or locate resources. They can be defined on two levels:

  • User level (current user only)
  • System level (all users, requires Admin)

The only program that I manually add it to PATH is MinGW-Win64 for C++ compilation. I use this method instead of using Visual C++ Redistributable that using lot amount of data and storages.

Let me show you how to add this to the path manually and using the command line

Set Environment Variable in PowerShell:

[Environment]::SetEnvironmentVariable("ENV_VALUE", "path/to/something", "{User, Machine}")
  • ENV_VALUE is depend on what kind of program you want to add
  • Path is absolute, relative path to executable program
  • User and Machine is role-level. Use User to add user-level variable ($var) and so on.

View or Check Current Value:

$Env:ENV_VALUE

[!note] Don’t Worry About PATH (When Using Package Managers). Relax! If you're installing apps using winget, scoop, or choco, you usually don’t need to manually set PATH.

These tools are Automatically add installed apps to PATH, Configure them correctly (e.g., Git, Node, Python), and Handle post-install scripts. for example:

winget install Git.Git -e --silent

This will install Git and add it to PATH — you're ready to use git right away in any terminal.

However, if you're manually placing executables or working with custom binaries, you might still need to:

  • Manually add folders to PATH
  • Set specific variables like JAVA_HOME, NODE_ENV, NVM, FNM etc.

If you’ve manually downloaded MinGW-w64 and want to use it from any terminal (like PowerShell, CMD, or Windows Terminal), you need to add its bin folder to your PATH environment variable.


Steps to Add MinGW to PATH (User or System)

1. Locate the bin directory

Example:

C:\mingw-w64\bin

If it’s installed under C:\Program Files\mingw-w64\, the full path may look like:

C:\Program Files\mingw-w64\mingw64\bin

2. Add to PATH using PowerShell

$mingwPath = "C:\mingw-w64\mingw64\bin"
[Environment]::SetEnvironmentVariable("PATH", $Env:PATH + ";$mingwPath", "User")
  • "User" sets the variable only for your account.
  • Use "Machine" (requires admin) to set system-wide:
[Environment]::SetEnvironmentVariable("PATH", $Env:PATH + ";$mingwPath", "Machine")

3. Restart your terminal

Changes will apply on the next terminal session.


Test It

Open PowerShell or CMD and type:

gcc --version

If successful, you’ll see GCC’s version info. If not, recheck the path to bin.