To remove multiple environment variables in Linux, you can use the unset command followed by the names of the variables you want to remove. Here’s how to do it:
Open your terminal.
Use the
unsetcommand: You can remove multiple variables in a single command by listing them afterunset. For example:unset VARIABLE1 VARIABLE2 VARIABLE3Replace
VARIABLE1,VARIABLE2, andVARIABLE3with the names of the variables you want to remove. For example:unset MY_VAR1 MY_VAR2 MY_VAR3Verify the Variables are Removed: You can check if the variables have been removed by using:
echo $MY_VAR1 echo $MY_VAR2 echo $MY_VAR3If the variables have been successfully removed, these commands will not output anything.
Note:
- Similar to removing a single variable, using
unsetwill only affect the current shell session. To permanently remove variables, you need to delete or comment out their definitions in the shell configuration file (like~/.bashrcor~/.zshrc) and then source the file or restart the terminal.
