Article Title: Linux environment variable settings-summary. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1. Introduction
In linux, If you download and install an application, it is very likely that the prompt "command not found" appears when you type its name. If you find the executable file in the installation target folder every time, it is too cumbersome to find the executable file. This involves setting the environment variable PATH, and the PATH setting is also an integral part of customized environment variables in linux. Based on RedHat 9.0, this article describes how to customize environment variables in detail.
2. Introduction to variables
Linux is a multi-user operating system. Each user logs on to the system and has a dedicated runtime environment. Generally, the default environment of each user is the same. The default environment is actually the definition of a set of environment variables. You can customize your running environment by modifying the corresponding system environment variables.
3. Customize Environment Variables
Environment variables are closely related to Shell. A Shell is started after the user logs on to the system. For Linux, bash is generally used, but you can reset or switch to another Shell. Based on the release version, bash has two basic system-level configuration files:/etc/bashrc and/etc/profile. These configuration files contain two different variables: shell variables and environment variables. The former is only fixed in a specific shell (such as bash), and the latter is fixed in different shells. Obviously, shell variables are local, while environment variables are global. Environment variables are set through Shell commands. The configured environment variables can be used by all programs run by the current user. For the bash Shell program, the corresponding environment variables can be accessed through the variable name, and the environment variables can be set through export. The following describes several instances.
3.1 Use the echo command to display environment variables
--------------------------------------------------------------------------------
# In this example, echo is used to display common variables HOME
$ Echo $ HOME
/Home/lqm
--------------------------------------------------------------------------------
3.2 set a new environment variable
--------------------------------------------------------------------------------
$ Export HELLO = "Hello !"
$ Echo $ HELLO
Hello!
--------------------------------------------------------------------------------
3.3 Use the env command to display all environment variables
--------------------------------------------------------------------------------
$ Env
SSH_AGENT_PID = 1875
HOSTNAME = lqm
SHELL =/bin/bash
TERM = xterm
History Size = 1000
......
--------------------------------------------------------------------------------
3.4 use the set command to display all locally defined Shell Variables
--------------------------------------------------------------------------------
$ Set
BASH =/bin/bash
......
--------------------------------------------------------------------------------
3.5 run the unset command to clear environment variables.
--------------------------------------------------------------------------------
$ Export TEST = "test" # Add an environment variable TEST
$ Env | grep TEST # This command has output to prove that the environment variable TEST already exists.
TEST = test
$ Unset $ TEST # Delete the environment variable TEST
$ Env | grep TEST # This command has no output, proving that the environment variable TEST already exists
--------------------------------------------------------------------------------
[1] [2] Next page