How do I delete an exported environment variable?

 

To delete an exported environment variable in a Unix-like shell (e.g., Bash), you can use the unset command followed by the variable name you want to remove. Here's an example:

Suppose you have exported an environment variable named MY_VARIABLE like this:

bash
export MY_VARIABLE="Some value"

To delete or unset this environment variable, you can use the unset command:

bash
unset MY_VARIABLE

After running this command, the MY_VARIABLE environment variable will no longer be defined in the current shell session, and it will be removed from the environment.

Here's a step-by-step example:

  1. Open a terminal.

  2. Check if the environment variable exists and see its value by running:

    bash
  • echo $MY_VARIABLE

    If it exists, you'll see its value printed.

  • Use the unset command to delete the environment variable:

    bash
  • unset MY_VARIABLE
  • Verify that the environment variable has been deleted by running echo again:

    bash
    1. echo $MY_VARIABLE

      You should not see any output because the variable has been unset.

    This process works for removing any environment variable that has been previously exported in your shell session. Keep in mind that this only affects the current shell session; if you want to remove an environment variable permanently, you should remove or modify its definition in the appropriate configuration files (e.g., .bashrc, .bash_profile, or similar) depending on your shell and system configuration.

    Comments