Environment Variables: what they are, what purpose they serve and how we can edit them in Windows and Linux

Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on email
Share on whatsapp

Environment Variables: what they are, what purpose they serve and how we can edit them in Windows and Linux

Don’t need to be a programmer to have to have dealt in some cases with the environment variables. It may be, for example, that at the time of install or to configure any program for Windows I’ve found a route that, instead of following the typical structure “C:/Users/YoMismo/carpeta” show something like “%USERPROFILE%/folder”.

That is because %USERPROFILE% it is a environment variable: that is to say, a text string that operating systems such as Windows, Linux or Mac used to store values that can vary from one computer to another -or, as in this case, from one user to another – but that, however, they need a unified way of accessing the same.


Explícamelo more slowly

Normally, these values make reference to files, directories, and common functions of the system whose particular route may varybut other programs need to be able to know.

The above example allows a program to know to access your user folder even if you have not indicated the name of the same. Or even if you don’t know what version of Windows you’re using (remember that the ‘C:Users’ Windows 10 was ‘C:Document and Settings’ in Windows XP).

Just the same, because all that information is defined in the environment variables, ensuring that all programs for Windows can perform its work properly on any computer. Because there are many more environment variables in addition to %USERPROFILE% . Let’s look at some:

  • %APPDATA% – Refers to the hidden folder for application data, within the user folder. In Windows 10 the default route is *”C:UsersNombreDeUsuarioAppDataRoaming”.

  • %COMMONPROGRAMFILES% – Refers to the folder where programs store common files. In Windows 10 the default route is “C:Program FilesCommon Files”.

  • %PROGRAMFILES% – Refers to the folder where programs are installed. In Windows 10 the default route is “C:Program Files”.

  • %WINDIR% – Refers to the folder where Windows is installed. In Windows 10 the default route is “C:Windows”.

But the environment variables do not always correspond to paths of directories: you can refer to other kinds of information. So, %TIME% returns the current system time, %OS% the version of the operating system and %PATHEXT% the list of file extensions considered executable (the common thing is that the list includes, in addition to .EXE, files like .BAT, the .COM, .CMD .JS., .The JSE, .MSC .VBE, .VBS, .WSF, .WSH, etc.).

But maybe the environment variable with the most commonly we will have to deal will be %PATH%. And what is its function? Do you noticed that, when tecleáis a command in Windows (for example, Regedit) it is not necessary to type the full path to the executable?

That is because, each time that you type a command, the system checks the folders contained in the variable %PATH% to check if an executable file matches the same.

It is a resource very used, for example, by the developers who wish to call in an interpreter or compiler from the project folder in which they are working; many IDE also resort to the %PATH% to run these tools.

Java Here is what happens when we call the interpreter from Java, but we have not included the directory of the JRE in the %PATH% of Windows.

Check and edit your environment variables in Windows

If you want to check if the values of those variables in your computer coincide with those presented here, can open a window of command prompt (CMD, not Power Shell) and type “ECHO” followed by the variable in question. If you prefer to list all the variables and their respective valuesgo (now) to the Power Shell and type “Get-ChildItem Env:”.

But if you don’t like to resort to the command line, there is another tool that will allow us not only to check the value of each variable, but also edit them in a very simple way. We only have to enter ‘advanced system Settings’ in ‘Search’, and open “environment Variables” in the window that we see. And we will see something like this:

Environment Variables In Windows 10 Environment Variables in Windows 10

Once we get to this point, we will only have to select the variable we want to change and click “Avoid”. We can also add new variables or delete them.

Variables command in Linux

In the case of Linux, the role of the environment variables is the same as in Windowsalthough we will not find exactly the same nor with the same names.

In this operating system, we resorting to the command ‘printenv’ to view both the complete list of variables as the value of each one of them individually.

Etc Environment Content of a file ‘/etc/environment’, viewed with the text editor Nano.

So, in Linux we find variables such as ‘SHELL’ (shell which will interpret the commands, in the majority of distributions will be Bash), ‘LANG’ (current language) or ‘HOME’ (home directory of current user).

To change their values, we will have to resort to edit, primarily, three text files:

  • “/etc/environment” – For independent variables of the command interpreter.

  • “etc/profile” – The variables that we define here are valid for all shells, interactive that require login. Its equivalent if we want to define only user variables is ~/.bash_profile.

  • “/etc/bash.bashrc” – As above, but for shells, non-login. Its equivalent if we want to define only user variables is ~/.bashrc.


The news

Environment Variables: what they are, what purpose they serve and how we can edit them in Windows and Linux

it was originally published in

Engadget

by
Marcos Merino

.

Environment Variables: what they are, what purpose they serve and how we can edit them in Windows and Linux 1