You can use the Export command to set environment variables, but it would be very annoying if you have to reset the environment variables every time you enter the system. Linux provides everyone with a way to automatically set environment variables, which is to change the .bashrc file. Generally speaking, there are two files that can provide this "automatically set when entering the system" function, one is /etc/bashrc and the other is ~/.bashrc. Among them, /etc/bashrc is executed by each user, while ~/.bashrc is only executed by the current user. Therefore, /etc/bashrc can only be changed by the root user, while ~/.bashrc is a private file for each user. "~" refers to the user's home directory.
When a user is created, Linux will allocate a directory for the user to use. For example, for "hjk41", the directory is "/home/hjk41". General users can only change files in this directory, so that users will not interfere with each other. Therefore, the ~/.bashrc file here is "/home/hjk41/.bashrc". If there is another user named "hjk42", then his .bashrc file is "/home/hjk42/.bashrc".
In this way, each user has his own independent ".bashrc" file, which can be changed as needed without interfering with each other. The /etc/bashrc file is shared, and there is only one copy in the entire Linux. Generally speaking, the user's "~/.bashrc" will call /etc/bashrc, so changing /etc/bashrc will affect all users. This file is generally managed by the root user.
In short, Linux will execute the corresponding .bashrc file when the user logs in. For example, when I log in, /home/hjk41/.bashrc will be executed, and this file first calls /etc/bashrc. The following is a simple .bashrc: if [ -f /etc/bashrc ]; then . /etc/bashrc fi export PATH=$PATH:/home/hjk41/bin The first three lines mean "if /etc/bashrc this The file exists, then execute it." The last line was added by myself to modify the PATH variable. In this way, every time I log in, the environment variable PATH will be automatically modified to what I need. "env" lists all environment variables "source ~/.bashrc" After changing the .bashrc file, execute the following command to make the changes take effect immediately (otherwise you will have to wait until the next login to see the effect).