Configuration file
In Linux systems, commonly used configuration files include:
- User level configuration file:
~/.bashrc
- System-level configuration files:
/etc/profile
There are some differences in functions and effects between user-level configuration files and system-level configuration files:
-
User level configuration file:
Location: Typically stored in the user's home directory, e.g.
~/.bashrc
Scope of application: Only effective for the current user, will not affect other users
Usage scenarios: Suitable for individual user-defined configurations. You can set personal environment variables, aliases, functions, etc.
-
System-level configuration files:
Location: By storing in the system's global configuration directory, for example
/etc/profile
Scope of application: It is effective for all users in the system and is a globally shared configuration.
Usage scenarios: Suitable for administrator or system level configuration, you can set system environment variables, global aliases, system startup scripts, etc.
User-level configuration files have higher priority than system-level configuration files. When the same environment variable exists at both the user level and system level, the user-level configuration will override the system-level configuration.
You can open and edit the configuration file through vim ~/.bashrc
the or gedit ~/.bashrc
command. Vim and gedit are both commonly used text editors.
environment variable
Environment variables can export VARIABLE_NAME=variable_value
be added to the configuration file by , where VARIABLE_NAME
is the environment variable name and variable_value
is the value of the environment variable.
export PATH=/usr/local/bin:$PATH
This is an example of setting environment variables. The specific explanation is as follows:
export
: This keyword is used to export the variable to the current shell environment, making it an environment variablePATH
:PATH
is a special environment variable that contains a colon-separated list of directories. The operating system will use this environment variable to find the path to the executable file. When a command is entered in the terminal, the operating system willPATH
sequentially search for the executable file of the command in the defined directory./usr/local/bin
: This is a directory path that will be/usr/local/bin
added toPATH
the environment variables./usr/local/bin
Is a commonly used directory used to store user-defined executable files$PATH
:$PATH
Indicates the value of an existingPATH
environment variable. In this example, add/usr/local/bin
toPATH
the beginning of the directory listing for the variable, and then add the original value. This is done so that the newly added path can be searched first to avoid conflict with other executable files that may exist with the same name.
In short, export PATH=/usr/local/bin:$PATH
it means that will /usr/local/bin
be added to PATH
the environment variable and retain the original PATH
value. In this way, when a command is entered, the system searches /usr/local/bin
the directory first and then searches in the original search order. /usr/local/bin
Doing this will allow you to run the executable file located in the directory directly in the terminal .
You can use echo $VARIABLE_NAME
the command to verify whether the environment variables are set successfully. For example, you can run echo $PATH
to print out PATH
the values of environment variables.