TECHNIG
Gateway for IT Experts and Tech Geeks

Windows Environment Variables Everything You Must Know

You will be counted as power user when you know how to use environment variables. Environment variables are everywhere in windows. This topic might be a little hard for beginner users to comprehend. You will empower to skill once you know how to use environment variables correctly. Windows environment variables are something that everyone should know about. If you don’t know about it yet, this article is for you. We will cover everything you need to know about it and how you can use it.

What Is An Environment Variable?

Environment variables describe or show the path to a program or somewhere in your operating system. Let’s say you want to know where a software is installed or what’s your computer name. You can use environment variables to find the answer to such questions.

Environment variables hold values related to the current environment, like the Operating System or user sessions.

The environment variable has a name and a value. For instance, OneDrive as name and C:\Users\UserName\OneDrive as value. 

Where to find the Environment Variables?

In Windows, You can find the env variables in your system properties.

Windows Environment Variables
Windows Environment Variables

You can specify your own path there. As you can see, there is two sections. The first one is for login user specific and the second is for your system.

user and system environment variables
user and system environment variables

What’s Path?

in short, Path is the path to an executable software. For example, if you run calc on the run, it will open the calculator. The calc is the variable name and the value is in the system directory.

Path in windows environment variable
Path in windows environment variable

How to Use Windows Environment Variables?

The usage is very common and simple. If you want to open any program from command prompt ( or run in windows ), use environment variable to do that. For example:

Your program is installed in C:\Program Files\Sublime Text 3. Now you want to run sublime on the run or cmd and it should open sublime text. 

There are two ways to set environment variables. Using command line, using GUI. You saw how you can access environment variables in the above section. Let’s see how you can use the command line to access and set variables.

Format

Environment Variables in Windows are denoted with percent signs (%) surrounding the name:

%name%

echo

To display an environment variable’s value in,cmd.exe type.echo %name%

C:\>echo %APPDATA%
C:\Users\BigHero\AppData\Roaming

set

To create or set a variable, use set variableName=value:

C:\>set subl=C:\Program Files\Sublime Text 3\subl.exe

C:\>set FunnyCatPicturesTwo=%USERPROFILE%\Pictures\Funny Cat Pictures 2

To append or add a variable, use set varname=value;%varname%:

C:\>set Penguins=C:\Linux

C:\>set Penguins=C:\Windows;%Penguins%

C:\>echo %Penguins%
C:\Windows;C:\Linux

Environment variables set in this way are available for (the rest of) the duration of the Command Prompt process in which they are set, and are available to processes that are started after the variables were set.

Setx

To create or set a variable permanently, use setx varname "value":

C:\>setx subl "C:\Program Files\Sublime Text 3\subl.exe"

[Restart CMD]
C:\>echo %subl%
C:\Program Files\Sublime Text 3\subl.exe

Unlike,set there is no equals sign and the value should be enclosed in quotes if it contains any spaces. Note that variables may expand to a string with spaces (e.g., %PATH% becomes C:\Program Files), so it is best to include quotes around values that contain any variables.

You must manually add setx to versions of Windows earlier than Vista.

So far, if you run subl in command prompt or Run, it will give

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

It’s because setx didn’t add the environment variable to the path. As we mentioned before, the path is used to execute any software. Here is how you can fix that.

  1. Adding sublime text path to Path environment variables.
  2. Using setx /M

Add manually.

add to path
add to the path

After you add, press enter and save.

Use setx /M

Open your command prompt as administrator. (search cmd and press ctrl+ shift + enter).

setx /M path "C:\Program Files\Sublime Text 3"

That is done now. You can run subl in the command line and it will open the sublime text.

Note: We don’t recommend the second way. Because it will override the system path variables.

Conclusion.

It was hard for me to understand how the Windows environment variables work. It took a little time but it worth learning and using. If you have any question, feel free to comment it below.

Leave A Reply

Your email address will not be published.