Linux
Published in Linux
avatar
2 minutes read

Deleting an Exported Environment Variable

In Linux, you can easily delete an exported environment variable using a few simple commands.

Viewing Exported Environment Variables

Before deleting an exported environment variable, it's a good idea to view the current list of exported variables to ensure you're removing the correct one. To do this, open your terminal and run the following command:

env | grep "VARIABLE_NAME"

Replace "VARIABLE_NAME" with the name of the environment variable you want to delete. This command will display the variable and its value if it is currently exported.

Unsetting the Environment Variable

To delete an exported environment variable, you can use the unset command followed by the variable name. This command removes the specified variable from the environment:

unset VARIABLE_NAME

Replace "VARIABLE_NAME" with the name of the environment variable you want to remove.

Verifying the Deletion

After running the unset command, the environment variable will be deleted. To verify that the variable has been successfully removed, you can again use the env command or echo the variable:

echo $VARIABLE_NAME

If the variable has been deleted, this command will not display any output.

Unsetting an Environment Variable with Export

Sometimes, environment variables are exported and set in the same command. To remove such a variable, you need to unset it with the same syntax, including the export keyword:

unset VARIABLE_NAME=value

Again, replace "VARIABLE_NAME" with the name of the environment variable you want to delete, along with its assigned value.

0 Comment