Have you ever come across something in your IT career that makes you think to yourself “How did I come this far having missed this for so many years?” I had one of those moments this morning when it dawned on me that I didn’t instinctively know how to create or update environment variables in Windows, specifically the system “path” variable.
Typically, when I run across something like this I write about it because it helps me to understand it and it documents it so I don’t have to go “a-googling” at some point in the future. Onward and upward and all that jazz…
What are Environment Variables?
Rather than re-invent the wheel, I just stole a good description from elsewhere:
“An environment variable is a dynamic “object” on a computer, containing an editable value, which may be used by one or more software programs in Windows. Environment variables help programs know what directory to install files in, where to store temporary files, and where to find user profile settings. They help shape the environment that the programs on your computer use to run.”
SOURCE: ComputerHope.com
What is the difference between “System” and “User” Environment Variables?
In like fashion, I stole this answer from Stack Overflow:
“System environment variables are globally accessed by all users.
User environment variables are specific only to the currently logged-in user.”
SOURCE: StackOverflow.com
What is the PATH variable?
And… third time is a charm – from Wikipedia:
“PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.”
SOURCE: Wikipedia.com
Putting it all Together… why does it matter?
Rather than giving a long explanation I will just give my use case and hopefully it will make sense… I am learning Terraform. Terraform is a small executable application that you run against template files to build infrastructure on a given cloud platform (Azure, AWS, GCP). You call Terraform from the command line in Windows. So in my example I placed the “terraform.exe” file in “c:\terraform\terraform.exe”. If I don’t update the PATH variable in windows with “c:\terraform\” then the only way for me to call the program is (from the command line) to either change into the directory first or reference the full path to the executable every time I use it. If I update the PATH variable with that folder location, I can make my life much easier and just type “terraform” and Windows will look for an executable in that folder (and all the other folders in the PATH variable) with that file name and call it.
Example – no updated PATH variable:
Example – updated PATH variable:
How to update the System PATH environment Variable in Windows
From an elevated command prompt, updating the PATH variable for my use-case with Terraform looks like this:
Or from Powershell:
Super simple… Finally, if you ever want to review ALL of the different folders you might have set as PATHS in this variable, you can do so from the Windows GUI from the System Properties Panel… Instructions Here If Needed. Alternatively, these are variables so you can just use ECHO to see contents:
Conclusion: We all have blind spots
This is probably considered the basics to many folks and I almost feel a bit odd writing an article about it. To that end I can only plead like the fictional Roy Trenneman, “everyone has their blind spots.”
Cheers!