The hard way to learn Linux: the usage of environment variable files

In the Linux system, environment variables can be divided into system-level environment variables and user-level environment variables

System-level environment variables: all users can read
User-level environment variables: only the current user can read

System level

/etc/profile
is the first file used by the operating system to customize the user environment when logging in. This file sets environment information for each user of the system. When the user logs in for the first time, the file is executed.

/etc/environment
runs when the system starts, and is used to configure environment variables that are related to system operation but have nothing to do with users. Modifying the environment variables configured in this file will affect the whole world.

/etc/bashrc
executes this file for each user running the bash shell. When the bash shell is opened, the file is read.

User level

~/.profile
is executed when the user logs in, and each user can use this file to configure their own shell information.

~/.bashrc
This file contains bash information specific to your bash shell, which is read when you log in and every time you open a new shell.

~/.bash_profile
This file is executed only once when the user logs in.

Insert picture description here

command

Source FileName
function: Read and execute the command in FileName in the current bash environment, and it will take effect immediately.

source ~/.bash_profile
source ~/.bashrc
source /etc/profile

vi ~ / .bash_profile
vi ~ / .bashrc
vi / etc / profile

View environment variables: env
output environment variables: echo $JAVA_HOME

Guess you like

Origin blog.csdn.net/weixin_43173093/article/details/108074123