Windows and MS-DOS Environment variables
Environment variables are a mechanism of the operating system to store information. This information is used by both the operating system and other programs.
An example is the PATH variable. When we ask the operating system to run a program, it looks for it in the directories listed in this variable.
Another example is JAVA_HOME. Many programs that use Java, look for the JAVA_HOME variable, to know where is Java installed. Eclipse development tool is one of them.
How to access and modify MS-DOS environment variables.
It is often necessary to access or modify environment variables from batch files or lot processing. In Windows, these files usually have the extension "bat".
You may also access the environment variables from the MS-DOS console. Below, we can see what MS-DOS commands can be used for this:
- To access an environment variable we can use the ECHO command:
Eg: ECHO JAVA_HOME and the answer will be something like: C:\Program Files\Java\jdk1.7.0_45
- To modify the value of the variable we can use the SET command:
Eg: SET JAVA_HOME = C:\Program Files\Java;
-
In the particular case we want to add more content to a variable without losing the existing (a common case is when we want to add a new directory to the PATH) we can use SET PATH=%PATH%;<new directory>;
Eg: SET PATH=%PATH%;C:\Windows
Environment variables in Windows
The modifications you make to environment variables in the console, only affect the console session and will be lost when the console is closed. If we want changes to persist when we turn off the computer, we will have to make them in the Windows environment.
Steps:
Find "Control Panel \ System" from the start menu.
We can also reach the same point by clicking the right mouse button on the "My Computer-properties" button, from the file browser, or from the start menu.
Click on advanced system settings:
Click on the environment variables button, on the Advanced tag.
Choose the variable we want to delete or edit or create a new one.