What are environment variables
There is also one in windows
Linux environment variables
env
linux and windows environment variables, the function is similar, the environment variables of the windows system can call programs to run in cmd. The execution path of these programs is generally edited in the path variable
. Environment variables are divided into global or user-level
What are environment variables
The environment variable is a group of information records, the type is KV structure (keyValue, name=value), used to record the key information of the operating system. The environment variable of
the Linux series , you can use the command env to view the environment variable information of the current system configuration
$ symbol, Information about these environment variables can be obtained
Temporary effective
export variable name = variable value, it will be invalid when the terminal is closed and
permanently effective
- Effective for the current user, configured in the current user level: ~/.bashrc file
- Effective for all users, configured at the system level: /etc/profile file
The source configuration file will take effect immediately or log in to the terminal again to take effect
Configured at the user level in the ~/bashrc file
export variable name=variable value# configured in ~/.bashrc file
Configured at the system level in the /etc/profile file
export variable name=variable value# Configured in the /etc/profile file, effective for all users
Get information about these environment variables
echo $variable name ${variable name}
The PATH
environment variable PATH will record a set of directories separated by: . The record here is the search path for the system to execute the command, which has the same effect as the environment variable path in windows. When executing the command, it will search for the command to be executed one by one
from the destination recorded in the record and execute it. By modifying the value of this item, add a custom command search path
Add custom command search path case
(1) Create file
mkdir ~/zenX # create directory
touch testenv # create file
vim edit this testenv
Set the execution permission of this file. Don’t forget
to configure the user-level or system-level environment variable PATH
sudo vim ~/.bashrc # user level
sudo vim /etc/profile # system level
Settings take effect
source ~/.bashrc # user-level effective command
source /etc/profile # system-level effective command
Check whether the PATH value is valid
At any time, regardless of the directory, you can execute the testenv command
printenv ${environment variable}
printenv environment variable name View the value of the specified environment variable
echo $environment variable name | ${environment variable name} View the value of the specified environment variable
unset environment variable name clears the specified environment variable