Reputation: 38234
Before installing gnuplot, I set the environment variable GNUPLOT_DRIVER_DIR = /home/gnuplot/build/src
. During the installation, something went wrong.
I want to remove the GNUPLOT_DRIVER_DIR
environment variable. How can I achieve it?
Upvotes: 2511
Views: 1842700
Reputation: 756
First find which script file defines and adds the variable to the environment.
Look in folder /etc for files like profile, bash.bashrc, .bashrc file, .bashrc_login, etc.
And look for similarly named files in the user's home directory.
If it's not in any of those, it's likely that it's in some script file that was part of an installed package. For example, the package SDKMAN (for managing alternate SDK versions) creates a variable called DERBY_HOME. To find the script file creating it, apply the following search command to the /etc folder:
sudo egrep -lir THE_VAR_NAME /etc
This should produce some output like:
/etc/profile.d/jdk.sh
/etc/profile.d/jdk.csh
The separate file jdk.csh is needed for the C-shell environment if users have defaulted to it.
Once found it is simply a matter of navigating to the folder containing the script files, in this case here /etc/profile.d/ and then editing the files (with admin permission), removing the variable assignments and saving:
cd /etc/profile.d/
sudo gedit jdk.sh
sudo gedit jdk.sh
Of course, in this case the package setting the environment variable is in use, so I kept it.
But if the package were not in use and the environment variables dead weight to the startup process, then it should be deleted.
Use the process shown in this YouTube video.
Upvotes: 1
Reputation: 25080
On Linux and macOS, you can use the command unset
to remove an environment variable.
unset GNUPLOT_DRIVER_DIR
You can edit your shell profile file, such as .bashrc
or .bash_profile
in the /etc/profile.d
directory and remove the line that exports the variable.
.bashrc file:
nano ~/.bashrc
Then, search for the line export GNUPLOT_DRIVER_DIR
and delete it. Then save the file.
use the setx
command to delete an environment variable.
setx GNUPLOT_DRIVER_DIR ""
You can find more information about environment variables and how to manage them in the following links:
Upvotes: 29
Reputation: 440
The original question doesn't mention how the variable was set, but:
In C shell (csh/tcsh) there are two ways to set an environment variable:
set x = "something"
setenv x "something"
The difference in the behaviour is that variables set with the setenv command are automatically exported to a subshell while variables set with set aren't.
To unset a variable set with set, use
unset x
To unset a variable set with setenv, use
unsetenv x
Note: in all the above, I assume that the variable name is 'x'.
Credits:
Upvotes: 33
Reputation: 154083
Test if the DUALCASE variable exists (empty output):
env | grep DUALCASE
It does not, so create the variable and export it:
DUALCASE=1
export DUALCASE
Check if it is there:
env | grep DUALCASE
Output:
DUALCASE=1
It is there. So get rid of it:
unset DUALCASE
Check if it's still there (empty output):
env | grep DUALCASE
The DUALCASE exported environment variable is deleted.
Unset all local variables back to default on login:
CAN="chuck norris"
set | grep CAN
Output:
CAN='chuck norris'
env | grep CAN # Empty output
exec bash
set | grep CAN
env | grep CAN # Empty output
exec bash
command cleared all the local variables, but not environment variables.
Unset all environment variables back to default on login:
export DOGE="so wow"
env | grep DOGE
Output:
DOGE=so wow
env -i bash
env | grep DOGE # Empty output
env -i bash
command cleared all the environment variables to default on login.
Upvotes: 258
Reputation: 41205
unset
is the command you're looking for.
unset GNUPLOT_DRIVER_DIR
Upvotes: 3902
Reputation: 333
As mentioned in the above answers, unset GNUPLOT_DRIVER_DIR
should work if you have used export
to set the variable. If you have set it permanently in ~/.bashrc
or ~/.zshrc
then simply removing it from there will work.
Upvotes: 12