Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Environment variables are a fundamental aspect of the Linux operating system, providing a way to influence the behavior of processes and applications. They are key-value pairs that can be used to store configuration settings and other information needed by the system and user applications. This article will guide you through the process of creating, modifying, and using environment variables in Linux.
Environment variables are dynamic values that can affect the way running processes will behave on a computer. They are used by the operating system and applications to store configuration settings and other important data.
Some common environment variables in Linux include:
PATH
: Specifies the directories in which executable programs are located.HOME
: The current user's home directory.USER
: The current logged-in user.SHELL
: The path to the current user's shell.To view all environment variables, you can use the printenv
or env
command:
printenv
or
env
To view a specific environment variable, use the echo
command:
echo $HOME
Environment variables can be set temporarily or permanently.
To set an environment variable temporarily, you can use the export
command in the shell:
export MY_VAR="Hello World"
This variable will be available in the current shell session and any child processes spawned from it.
To set an environment variable permanently, you need to add it to your shell's configuration file. For example, if you are using bash
, you can add the variable to the ~/.bashrc
or ~/.bash_profile
file:
echo 'export MY_VAR="Hello World"' >> ~/.bashrc
source ~/.bashrc
For zsh
, you would add it to the ~/.zshrc
file:
echo 'export MY_VAR="Hello World"' >> ~/.zshrc
source ~/.zshrc
To remove an environment variable, you can use the unset
command:
unset MY_VAR
To add a new directory to the PATH
environment variable, you can use the following command:
export PATH=$PATH:/new/directory/path
To make this change permanent, add the above line to your ~/.bashrc
or ~/.zshrc
file.
If you need to set the JAVA_HOME
environment variable to point to your Java installation, you can do so with the following command:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
To make this change permanent, add the above line to your ~/.bashrc
or ~/.zshrc
file.
Environment variables are a powerful feature in Linux that allow you to configure the behavior of your system and applications. By understanding how to view, set, and unset environment variables, you can take full control of your Linux environment.