Environment variables under ubuntu

Environment variables:

Parameters or variables in the current ubunto environment. It is used in the operating system to set some parameters of the operating system (a variable system value)

1. What is an "environment variable"?

Environment variables refer to the parameters used to specify the operating environment of the operating system in our ubunto operating system. It contains the running information that one or more applications need to use, such as the path environment variable in the Linux system. When the program is running, the system should not only search for the program under the current directory, but also find it in the path specified in path.

2. Environment variable storage:

Environment variables can be divided into system environment variables and user environment variables. For system environment variables, it is stored in the configuration file in the root directory; while user environment variables are stored in the home directory. The following figure shows the storage location of environment variables and the scope of different stored files. The environment variables stored in bashrc will be called by the system whenever bash is used, while the environment variables in the profile file will only be called once when the system is started and will not be called repeatedly.

3. Configuration of environment variables:

(1) Definition of local environment variables

It only takes effect under the current bash

方式1:export 环境变量名=环境变量值

方式2:环境变量名=环境变量值

 Example effect:

(2) Definition of individual user environment variables

Personal user variables only take effect under the current user

Use the vi command to add at the end of the file, and then use the source command to refresh the environment variable

#用于编辑bashrc文件
vim ~/.bashrc
#刷新
source .bashrc

 Example effect:

 

(3) System environment variables

applies to all users

After using the command to add, you need to restart the client to take effect

#添加系统环境变量
sudo vim /etc/profile

Example effect:

Guess you like

Origin blog.csdn.net/NXBBC/article/details/126061497