Environment variables operating systems based on Linux kernel are those variables that contain text information used by other programs during startup. They usually include General system parameters both graphical and command shell information about the user’s preferences, the location of certain files, and more. The values of such variables are specified, for example, numerals, symbols, paths to directories or files. Due to this, many applications get quick access to certain settings, and provide the ability for the user to edit or create new options.
Working with environment variables in Linux
In this article, we would like to discuss the basic and most useful information that relates to the surrounding environment. In addition, we will demonstrate how to view, edit, create and delete. Familiarity with the main options will help novice users navigate the management of such instruments and understand their value in the distribution. Before the analysis the most important parameters I would like to talk about the division of them into classes. This grouping is determined as follows:
The configuration files for user and system variables
As you already know from the description above, two of the three classes of variables in Linux are stored in separate files, which contains common configurations and optional parameters. Each object is loaded only when the right conditions and used for different purposes. I would also like to highlight the following elements:
/ETC/PROFILEis one of the system files. Available to all users and the entire system even when the remote input. The only limitation to it — the settings are not accepted if you open a standard “Terminal”, that is, in that location are no values from this configuration will not work.
/ETC/ENVIRONMENT— the broader counterpart of the previous configuration. It operates at the system level has the same options as the previous file, but now without any restrictions even when connecting remotely.
/ETC/BASH.BASHRCfile is only for local use, remote session, or connected via the Internet to operate, it will not. Is performed for each user separately when you create a new terminal session.
.BASHRCis specific to the user, stored in his home directory and is executed every time when you start a new terminal.
.BASH_PROFILE— same thing .BASHRCis only for remoting, for example, when using SSH.
View the list of system environment variables
You can manually look everyone in the Linux system and user variables and their concepts with just one command, which displays the list. For this you will need to complete a few simple steps through a standard console.
sudo apt-get install coreutilsto check the availability of this utility you have in the system and immediately install it if necessary.
printenvand press Enter.
A list of key system and user environment variables
Thanks to the instructions above, you now know how you can quickly identify all current parameters and their values. It remains only to deal with main. Note I would like on these items:
DE. Full name — Desktop Environment. Contains the name of the current desktop environment. Operating systems on Linux kernel and used by various graphical frontend applications so it is important to understand what is currently active. This helps the variable DE. An example of its values — gnome, mint, kde and so on.
PATH— specifies a list of directories in which to search for various executable files. For example, under the action of one of the teams to search for and access the objects they refer to these folders for quick retrieval and transmission of executable files with the specified arguments.
SHELL— keeps the active command shell. Such wrappers allow the user to independently prescribe certain scripts and to run different processes with the help of syntaxes. The most popular shell is considered to be a bash. The remaining list of common commands to familiarize you will find in our other article on the following link.
HOME— here everything is quite simple. This parameter specifies the path to the home folder of the active user. Each user is different and it has the form: /home/user. The explanation for this value is also light — this variable, for example, used by programs to establish a standard location of their files. Of course, the examples there is a huge amount, but for reference that’s enough.
BROWSER— contains a command to open a web browser. This variable often determines the default browser and all other utility and refer to this information to open new tabs.
OLDPWD. All actions from the console or GUI originate from a particular location in the system. The first parameter is responsible for the finding, and the second shows the previous. Accordingly, their values change quite often and are stored in custom configurations and in the system.
TERM. Programs-terminals for Linux, there are many. Mentioned variable keeps information about the name of the active console.
RANDOM— contains a script that generates a random number from 0 to 32767 when referring to this variable. This option allows other software to dispense your own random number generator.
EDITOR— responsible for editing text files. For example, by default you can see the path /usr/bin/nano, but nothing will interfere to change it to any other. For more complex actions with the test meets
VISUALand runs, for example, the editor vi.
HOSTNAME— the computer name and
USER— name of the current account.
Running commands with the new environment variable values
Can to change the option to any option to run with it a certain program or perform any other actions. In this case, in the console you will only need to specify env
VAR=VALUEwhere VAR is variable name and VALUE is its value, for example, the path to the folder
The next time you view all parameters using the above command
printenv you will see that the specified value has changed. However, it will be like it was default, immediately after the following reference to it, and operates only within the active terminal.
Installation and removal of local variables
From the material above, you already know that local settings are not stored in the file and is only active in the current session, and thereafter discarded. If you are interested in their own create, and delete these options, do the following:
VAR=VALUE, then press Enter. As usual, VAR — any variable name in one word, and VALUE is the value.
echo $VAR. The line below you need to the option variable.
unset VAR. Check the uninstall can also be through
echo(the next line must be empty).
So uncomplicated way adds any local settings in an unlimited number, it is important to remember only the main features of their action.
Adding and deleting custom variable
We moved on to classes of variables that are stored in configuration files, and it comes up that you have to edit the files themselves. This is done using any standard text editor.
sudo gedit .bashrc. We propose to use image editor with syntax notation, for example, gedit. However, you can specify any other, for example, vi or nano.
export VAR=VALUE. The number of such parameters is not restricted. In addition, you can change the value of variables already present.
If you before making any changes, didn’t read the description of this class of variables, be sure to read the information at the beginning of the article. This will help to avoid further errors with the action of the input parameters with their limitations. With regard to the removal of options occurs it is also via the configuration file. Enough delete the line completely or comment it by adding in the beginning of the sign #.
Create and delete system environment variables
It remains only to raise the third class of variables — system. Edited for this file is /ETC/PROFILE, which remains active even when connecting remotely through, for example, is known to many Manager SSH. The opening of the CI is approximately the same as in the previous version:
sudo gedit /etc/profile.
The changes to the file will remain even after restarting the session and each user and application will be able without any problems to access the new data.
Even if the information submitted today seems very complicated, it is strongly recommended to understand it and to understand as many aspects. The use of such tools the OS will help to avoid the accumulation of additional configuration files for each application, since they will all refer to variables. It also protects all parameters and grouping them within a single location. If you are interested in a specific, little-used environment variables, consult the documentation of your Linux distribution.