To remove an environment variable in Linux, you can use the unset command. Here’s how to do it:
-
Open your terminal.
-
Use the
unsetcommand:
To remove an environment variable, type the following command:unset VARIABLE_NAMEReplace
VARIABLE_NAMEwith the name of the variable you want to remove. For example, to remove a variable namedMY_VARIABLE, you would use:unset MY_VARIABLE -
Verify the Variable is Removed:
You can check if the variable has been removed by using:echo $MY_VARIABLEIf the variable has been successfully removed, this command will not output anything.
Note:
- The
unsetcommand only removes the variable from the current shell session. If you want to remove a variable permanently, you need to delete or comment out its definition in the shell configuration file (like~/.bashrcor~/.zshrc) and then source the file or restart the terminal.
