In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what Linux environment variables are related knowledge, detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that everyone will have a harvest after reading this Linux environment variable article, let's take a look at it.
Linux systems are multi-user task systems, for each user can specify specific user variables, Linux systems can function properly and provide services to users, requiring hundreds of environment variables to work together.
01 Environmental variables
Environment variables are often encountered during Linux development, so what are environment variables? Many friends don't have a special understanding of environment variables when they first learn Linux. Shouldn't variables be similar to global variables and local variables in programming languages? Why is there an environmental variable?
In our mainstream OS, almost all of them have the concept of environment variables, and there are also environment variables under windows, as shown in the following figure:
In fact, these so-called environment variables are equivalent to the abbreviation of some information, such as search, query path, etc., after the application can obtain the information contained in these environment variables to complete the corresponding work, many small partners have such experience, often in windows running just installed software will need to add some path information in the environment variables, otherwise the software can not run.
In Linux, a similar function is used. When a command is executed, the system searches according to the path information in the environment variable until it finds the corresponding program to run.
02 Linux Environment Variables
Linux environment variables are mainly divided into system level and user level, which is also very similar to windows, as shown in the following figure:
Different levels of environment variables exist in different configuration files in linux systems, and their scope is also different, so it is more convenient to understand the so-called environment variables by combining the scope of various variables in C language, which is also a resident memory identifier.
We can view all environment variables by typing printenv in linux interrupt:
One of the more commonly used is the environment variable PATH, which can be viewed separately using printenv PATH or echo $PATH, as shown in the following figure, which is exactly the same:
PATH environment variable is divided by colon: to form multiple paths. When the user enters the corresponding command, the program will query the program from the above path to execute.
For example, if you type ls command line in terminal, Shell will find ls executor from path stored in PATH variable to run.
03 Modify environment variables
Or take the picture above:
There are two ways to modify environment variables:
1 ) Use export command line to import directly;
2 ) Save the export command line to the corresponding file as shown in the figure above to load and import it at the right time.
For command import method is temporary, and save to the corresponding file can override its scope into effect.
Example of Method 1:
1. Use the command line "export environment variable = newly added value:$environment variable", as shown in the following figure, so that a new path is added.
2. When exiting the terminal and re-entering, the environment variables temporarily added by using export will disappear.
3, this way of directly using the command line, can take effect immediately, and only for the current user, when reopening the terminal will be invalid.
Example of Method 2:
1, relative to the command line mode, in fact, just put the export command line into the corresponding file to load and use, we enter the home directory, and then edit the hidden file.bashrc, and then add the command line to the end, as shown in the following figure:
2, after adding to the file and saving, its environment variables will not take effect immediately, you need to use the source command to execute it before it can take effect.
Restart the terminal, as shown in the following figure, its environment variables still exist, because ~/.bashrc contains bash information of the shell, when logging in and every time you open a new shell, the file is read, and the corresponding command will be re-executed.
4. The above modification.bashrc is only loaded when the shell is started, and the programs executed before it is loaded are invalid, so there are different scopes, such as environment variables stored in ~/.profile, so the graphical interface launcher can access the set environment variables, while those set to ~/.bashrc cannot be accessed by the graphical interface launcher.
5. For ordinary users, the environment variables can be operated in the.bashrc file. If other configurations with a wider scope are modified, other users will be affected. At the same time, these configuration files are also overwritten step by step. The files loaded later in the startup process will overwrite the same configuration information as before.
The content of this article on "What are Linux environment variables" is introduced here, thank you for reading! I believe everyone has a certain understanding of "what Linux environment variables are." If you want to learn more, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.