SUMMARY
This article explains how to permanently delete or temporarily unset environment variables for supported versions of Windows, macOS and Linux. Environment variables are dynamic-named values which can be used to alter the behaviour of a process that uses them.
MORE INFORMATION
Deleting environment variables permanently
Deleting environment variables permanently ensures that the variables are removed system wide. Below are instructions for how to permanently delete environment variables set on each OS:
Windows
-
Type "env" in the Windows Taskbar Search and select Edit the system environment variables.
-
Click the Environment Variables... button.
-
Select the environment variable you want to delete and click Delete.
- Click OK.
NOTE: When deleting either user or system variables, you may need to log off and on again before your changes to environment variables take effect.
macOS
macOS has a few ways that environment variables could be set: launchd.conf, .plist, or shell config file. Make sure to delete the environment variable using all methods you used to create the environment variables and where you’ve stored them.
If you used the launchd.conf file to set environment variables:
- Open the Terminal app.
-
Enter the following command and confirm your password when prompted to:
sudo vi /etc/launchd.conf
- Use the arrow keys to move the cursor to the environment variable you want to delete.
TIP: Environment variables use either of the following formats:setenv <VARIABLE> <VALUE>
orexport VARIABLE = value
- Delete the line by pressing the [D] key twice (
dd
) on the keyboard. - To save and quit, type [:] and [X] (
:x
) then press [Enter] on the keyboard.
TIP: If you want to undo, press the [Esc] key, type [:] and [U] (:u
), and then press [Enter].
If you used a .plist file to set environment variables:
-
Open the
~/Library/LaunchAgents/my.environment.plist
file with the editor of your choice, like TextEdit.
NOTE: my.environment may be named differently. Please check all files in~/Library/LaunchAgents
if unsure.
TIP: To navigate to~/Library/LaunchAgents
, open Go to the folder with [Command]+[Shift]+[G].
- Delete the entire line of the environment variable and value in the file. Environment variables will use the following format:
launchctl setenv MY_VARIABLE my_value
- Save the .plist file.
If you used a shell config file, see the Linux section below for more information on how to delete them.
Restart your Mac to apply the changes.
Linux
- The procedure for setting an environment variable depends on your system's default shell. Open a Terminal window and enter the following to get the name of your shell:
echo "$SHELL"
- Depending on the output of the previous step, do one of the following:
-
- If your shell is a csh or tcsh, delete the environment variable and value from the .cshrc or .tcshrc files.
TIP: Environment variables use the following format:setenv VARIABLE value
. For example:setenv NUKE_PATH /SharedDisk/Nuke
-
If your shell is a bash, ksh, or zsh, delete the environment variable and value from the .bashrc or .kshrc files.
TIP: Environment variables use the following format:export VARIABLE = value
. For example:setenv NUKE_PATH=/SharedDisk/Nuke
- If your shell is a csh or tcsh, delete the environment variable and value from the .cshrc or .tcshrc files.
NOTE: If you don’t want to delete your environment variables, comment them out to unset them. For example, if you’re using bash, you can add # in front of the environment variable to turn that line into a comment.
NOTE: If you have set environment variables in any other files, make sure you delete or unset them as well.
Unsetting environment variables temporarily
Unsetting environment variables temporarily allows you to troubleshoot by changing a particular environment variable just for that Command Prompt/Terminal session. Other sessions on the same system will continue to use the environment variables you unset in that session. Below are instructions for how to temporarily unset environment variables set for each platform:
Windows
- Launch the Command Prompt app.
- Unset the environment variable by executing the
set
command but setting the value to nothing, for example:set NUKE_PATH=
- Launch your application from the same Command Prompt session for it to not have that environment variable set.
macOS
-
Launch the Terminal app.
-
Unset the environment variable by executing the
unset
command with your variable's name, for example:unset NUKE_PATH
-
Launch your application from the same Terminal session for it to not have that environment variable set.
Linux
- The procedure for setting an environment variable depends on your system's default shell. Open a Terminal window and enter the following to get the name of your shell:
echo "$SHELL"
- Depending on the output of the previous step, do one of the following:
- If your shell is a csh or tcsh shell, then unset the environment variable by executing the
unsetenv
command with your variable's name, for example:unsetenv NUKE_PATH
- If your shell is a bash or ksh shell, then unset the environment variable by executing the
unset
command with your variable's name, for example:unset NUKE_PATH
- If your shell is a csh or tcsh shell, then unset the environment variable by executing the
- Launch your application from the same Terminal session for it to not have that environment variable set.
FURTHER READING
More information about handling environment variables can be found in the following articles:
Q100015: How to set environment variables
Q100017: How to list environment variables
Q100679: How to get environment variable values
We're sorry to hear that
Please tell us why