In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to set environment variables under linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Then you need to write the export command to a system file. The common files with this function are as follows:
/ etc/environment or / etc/profile or ~ / .profile or / etc/bash.bashrc or ~ / .bashrc, etc.
With so much to use, what's the difference between them? who comes first?
First, let's take a look at what these files are for:
The first file read by the system when logging in is used to set environment variables for all processes. When the system uses this file, it does not execute the commands in this file, but assigns VALUE to KEY according to the code of KEY=VALUE mode, so if you want to define PATH environment variables in the file, you only need to add a line of code like PATH=$PATH:/xxx/bin.
The second file executed when the system logs in, which can be used to set the environment variables for all users of the system.
3.Compact .profile-> is the profile file corresponding to the currently logged-in user, which is used to customize the personal work environment of the current user.
4. Bash bash bash.bashrc-> is an initialization file for all users, and the environment variables set here will be applied to all users' shell, and this file will be executed every time the user opens the bash.
5.bashrc-> is the bash initialization file corresponding to the currently logged-in user, which will be executed every time the user opens shell.
Then, according to the above description, the order of execution of these files should be:
/ etc/enviroment-> / etc/profile-> ~ / .profile-> / etc/bash.bashrc- > ~ / .bashrc
To verify that this order is correct, we can do a little experiment here, assuming that our login user name is xyz. Add a line to / etc/environment:
ENV_MSG= "this is / etc/environment"
This means adding an environment variable ENV_MSG, and then adding two lines of code to / etc/profile:
Echo $ENV_MSG > > / home/xyz/log.txt
Echo "this is / etc/profile" > > / home/xyz/log.txt
In this way, if / etc/environment is read by the system before profile, the value of EVN_MSG and the message this is / etc/profile will be printed in / home/xyz/log.txt.
Add a line of code to / home/xyz/.profile:
Echo "this is .profile" > > / home/xyz/log.txt
Add a line of code to / etc/bash.bashrc:
Echo "this is / etc/bash.bashrc" > > / home/xyz/log.txt
Add a line of code to / home/xyz/.bashrc:
Echo "this is .bashrc" > > / home/xyz/log.txt
Then, restart the computer to see what the log.txt file looks like.
After starting the computer, log in as the xyz user and immediately open / home/xyz/log.txt, you can see the following three lines of messages in the file:
This is / etc/environment
This is / etc/profile
This is .profile
This shows that the system reads and executes the contents of / etc/enviroment, / etc/profile, and ~ / .profile in turn during the login process.
Then open a shell window and two lines of messages will be added to the log file:
This is / etc/bash.bashrc
This is .bashrc
This shows that in the process of opening shell, the system executes / etc/bash.bashrc and ~ / .bashrc in turn. If you close the shell window and open a new shell window again, two more lines of the same message will be added to the log file. From this, we can know that each time a new shell is opened, the system will repeat the execution of these two files without touching the contents of the first three files.
Next, we open / etc/environment, change the line we just wrote to ENV_MSG= "this is not / etc/environment", then log out, log in again as xyz, and we will find that there are three more lines in the log file:
This is not / etc/environment
This is / etc/profile
This is .profile
This shows that logging out and re-logging in will also cause the system to read and execute these three files.
This is the end of the content of "how to set environment variables under linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.