How to set and manage Linux environment variables requires specific code examples
In the Linux operating system, environment variables are dynamic values stored in the operating system. They are used to control the behavior and output of various programs. Setting and managing environment variables is very important in Linux systems. This article will introduce how to set and manage Linux environment variables, with specific code examples.
In Linux systems, we can view the value of environment variables through the echo $VARIABLE_NAME
command, such as viewing the PATH environment The value of the variable can be determined using the echo $PATH
command.
To set temporary environment variables, you can use the export
command, for example:
export VARIABLE_NAME=value
hereVARIABLE_NAME
is the name of the environment variable, value
is the value of the environment variable. Once set, this environment variable is only valid in the current session.
To set permanent environment variables, you can edit /etc/profile
, ~/.bashrc
or ~/.bash_profile
and other files, add the following content:
export VARIABLE_NAME=value
Then run source /etc/profile
or source ~/.bashrc
Make environment variables effective.
You can delete existing environment variables through the unset
command, for example:
unset VARIABLE_NAME
This will Delete the environment variable named VARIABLE_NAME
.
The following is a specific example that demonstrates how to set up an environment named MY_VARIABLE
with a value of hello
Variable:
export MY_VARIABLE=hello echo $MY_VARIABLE
After running the above code, if no error is reported, it means that the value of the environment variable MY_VARIABLE
is successfully set to hello
, and echo $ MY_VARIABLE
can verify the value of environment variables.
Through the above steps, you can easily set and manage Linux environment variables. Remember to choose how to set environment variables temporarily or permanently according to your own needs, and verify whether the environment variables are set successfully in a timely manner. Hope the above content is helpful to you.
The above is the detailed content of How to set and manage Linux environment variables. For more information, please follow other related articles on the PHP Chinese website!