Linux PATH environment variable

Source: Internet
Author: User

$PATH: Determines to which directories the shell will look for commands or programs, the value of PATH is a series of directories, and when you run a program, Linux searches for the compiled links in these directories

Output path value under Shell:

Echo $PATH:

Windows is%path%;

Path= $PATH: <path 1>:<path 2>:<path 3>:------: <path n> separated by semicolons.

A one-line bash command is required: Export path= $PATH:/usr/locar/new/bin This command means: Make PATH self-increment:/usr/locar/new/bin, path=path+ ":/usr/locar/new/ Bin "; The path of the above method will be lost after the terminal is closed . So it is recommended to edit the/etc/profile to change the path, you can also change the. BASHRC (i.e.: ~/.BASHRC) in the home directory. The usual practice is to write the Bash command to the end of/ROOT/.BASHRC, and then when you re-login to Linux (it should be executed when Linux starts), the new default path is added. Of course, you can also directly use the command: SOURCE/ROOT/.BASHRC execute this file to re-login.

What is the difference between/etc/profile and/etc/environment files in Linux?

This article reproduced: http://andy136566.iteye.com/blog/1025338

First add the export LANG=ZH_CN to/etc/profile, exit the system to log in again, login prompt display in English. Delete the export lang=zh_cn in/etc/profile, add LNAG=ZH_CN to/etc/environment, exit the system to log in again, sign in prompt to display Chinese. The user environment is established by always executing/etc/profile and then reading the/etc/environment. Why is it as different as the above?


The/etc/environment should be executed first and then executed/etc/profile.
/Etc/environment is the setting of the entire system environment, and/etc/profile is to set all the user's ring , the former is not related to the logged on user, the latter with the login user.
The execution of the system application can be irrelevant to the user environment, but it is related to the system environment, so when you log in, you see the prompt information, such as date, time information display format is related to the system environment Lang, default Lang=en_us, if the system environment LANG=ZH_CN, The message is in Chinese, otherwise it is in English.

For a user's shell initialization, the/etc/profile is executed first, and then the file/etc/environment is read. The/etc/environment is performed first for the entire system. Do you understand that correctly?
/etc/enviroment--/etc/profile-$HOME/.profile--$HOME/.env (if present)


/etc/profile is the environment variable for all users
/etc/enviroment is the environment variable of the system
the order in which the shell reads the system when logging in should be
/etc/profile->/etc/enviroment-$HOME/.profile-$HOME/.env
The reason should be the difference between the user environment and the system environment described by JTW.
(UNBUTNU. Profile default content is:

[Email protected]:~# Cat. Profile
# ~/.profile:executed by bourne-compatible login shells.

If ["$BASH"]; Then
If [-f ~/.BASHRC]; Then
. ~/.bashrc
Fi
Fi

MESG N

If the same variable has different values in the user environment (/etc/profile) and the system environment (/etc/environment), then the user environment should prevail.


(1)/etc/profile: This file sets the environment information for each user of the system, and the file is executed when the user logs on for the first time. and collect the shell settings from the configuration file of the/ETC/PROFILE.D directory.
(2)/ETC/BASHRC: Executes this file for each user running the bash shell. When the bash shell is opened, the file is read.
(3) ~/.bash_profile: Each user can use this file to enter the shell information dedicated to their own use, when the user log on, the file is only executed once! By default, he sets some environment variables to execute the user's. bashrc file.
(4) ~/.BASHRC: This file contains bash information dedicated to your bash shell, which is read when you log in and every time you open a new shell.
(5) ~/.bash_logout: Executes the file each time it exits the system (exiting the bash shell). In addition, the variables set in/etc/profile (global) can be applied to any user, while the variables set in ~/.BASHRC, etc. (local) only inherit variables from/etc/profile, they are "parent-child" relationships.
(6) ~/.bash_profile is the interactive, login way into bash run ~/.BASHRC is the interactive non-login way into bash normally the two settings are roughly the same, so the former usually calls the latter.

There are two types of work environment settings file environment settings file: System environment settings file and personal environment settings file 1.User work environment settings file in the system: Login environment settings file:/etc/profile Non-login environment settings file:/ETC/BASHRC 2. Environment settings file for user settings: Login environment settings file: $HOME/.bash_profile//This is where environment variable settings are not logged in Environment settings file: $HOME/.BASHRC//This is where the alias is defined the login environment: refers to the user's working environment after logging into the system non-logon environment: refers to the user environment used by the user to call the child shell again

--------------------------

Linux PATH environment variable

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.