Before proceeding further into much detail, let me clear one thing. All the changes to the system environment variables on the cmd – command line are valid only for the current window and are not permanently modified.
That is, when the cmd command line window is closed, it will no longer work. There are two ways to permanently modify environment variables: one is to modify the registry (this method is not currently tested), the other is through My computer -> Properties -> Advanced system setting -> Environment variables, to set the system environment variables. we will discuss both the method here i.e. Direct and CMD method.
What are Windows System Environment variables?
Window Operating system specifies some operating environment or parameters, such as temporary folder location and system folder location. “Path” is a variable which stores some commonly used commands directory path or address. When you run any programs that depend on some regularly used commands these environment variables finds the address of that command and execute the commands easily. The system variables are set by different programs.
How to check for system environment variables?
When you start the cmd – command line window and call a command. For example, if you type java and press enter then if the system environment has the variable java defined then it will show no error but if the java variable path is not defined then an error is thrown often as “Java is not an internal or external command, operable program or batch file“. This applies to every command.
If your spelling is not wrong and the computer has that program installed, then the error is caused because your path variable is not set up correctly i.e. you have not given the absolute path of your program. That simply means that the operating system do not know where to find your mention program.
How to Set Windows system environment variables
# Direct Method to Set Windows system environment variables
- On your Windows PC go to My computer -> right click anywhere and select Properties -> Advanced system setting -> Environment variables.
- Here you will see all the system variables defined on your PC.
- Now to set the new variable click on New under System variables and give the name of the variable and value is the path of the variable. for ex: “C:jdkbin” is the value for java home.
- Like that you can modify the existing variable by clicking on the edit and changing the values.
# Using CMD to Set Windows system environment variables
- To view all available environment variables type SET and press Enter.
- To see an environment variable value or path: Type set variable name for example, set java will show you the path or value of the path variable.
- To modify the environment variable: type set variable name = variable content for example, to set the java path variable value type set path = C:jdkbin or whatever is your address.
- To set an empty value: If you want to set a variable as empty, type set variable name =
- To add variables to the variable: Type set variable name =%variable name%; variable content. For example set path =% path%; c:programfilesprogram.exe to add c:programfilesprogram.exe to path. %path% is the environment variable.
- % ALLUSERSPROFILE% – Locates the location of all User Profiles locally .
- % APPDATA% – Locally Returns the default case where the application data is stored.
- % CD% – Returns the current directory string locally.
- % CMDCMDLINE% – Returns the exact command line used to start the current Cmd.exe.
- % CMDEXTVERSION% – The system returns the current version of the “command handler extension”.
- % COMPUTERNAME% – The system returns the name of the computer.
- % COMSPEC% – The system returns an exact path to the command line interpreter executable .
- % DATE% – The system returns the current date . Use the same format as date / t command.
- % ERRORLEVEL% – The system returns the error code of the most recently used command. Often a nonzero value is used to indicate an error.
- % HOMEDRIVE% – The system returns the local workstation drive letter that is connected to the user’s home directory. Based on the setting of the home directory value. The user’s home directory is specified in “Local Users and Groups”.
- % HOMEPATH% – The system returns the full path to the user’s home directory. Based on the setting of the home directory value. The user’s home directory is specified in “Local Users and Groups”.
- % HOMESHARE% – The system returns the network path of the user’s shared home directory. Based on the setting of the home directory value. The user’s home directory is specified in “Local Users and Groups”.
- % LOGONSEVER% – Local Returns the name of the domain controller that validates the current logon session.
- % NUMBER_OF_PROCESSORS% – The system specifies the number of processors installed on the computer.
- % OS% – The system returns the name of the operating system. Windows 2000 displays the operating system as Windows_NT.
- % PATH% – The system specifies the search path for the executable file .
- % PATHEXT% – The system returns a list of file extensions that the operating system considers executable.
- % PROCESSOR_ARCHITECTURE% – The system returns the processor’s chip architecture.
- % PROCESSOR_IDENTFIER% – The system returns the processor description.
- % PROCESSOR_LEVEL% – The system returns the model of the processor installed on the computer.
- % PROCESSOR_REVISION% – The system returns the system variable for the processor revision number.
- % PROMPT% – Returns the command prompt for the current interpreter . Generated by Cmd.exe.
- % RANDOM% – The system returns any decimal number between 0 and 32767 . Generated by Cmd.exe.
- % SYSTEMDRIVE% – The system returns a drive that contains the root directory of Windows(that is, the system root).
- % SYSTEMROOT% – The system returns the location of the Windows root directory.
- % TEMP% and % TMP% – The system and user return the default temporary directory used by the application that is currently available to the logged-on user. Some applications require TEMP, while other applications require TMP.
- % TIME% – The system returns the current time. Use the same format as time /t command. Generated by Cmd.exe.
- % USERDOMAIN% – Returns the name of the domain containing the user account locally.
- % USERNAME% – Returns the name of the user who is currently logged in.
- % UserProfile% – Locates the location of the current user’s profile locally.
- % WINDIR% – The system returns the location of the operating system directory.