$JAVA_HOME
will already have a definition on many systems without explicitly declaring it in /etc/environment
:
$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
That said, the unset
command will eliminate a variable. From: Unix / Linux - Using Shell Variables
Unsetting Variables
Unsetting or deleting a variable directs the shell to remove the
variable from the list of variables that it tracks. Once you unset a
variable, you cannot access the stored value in the variable.
Following is the syntax to unset a defined variable using the unset
command −
unset variable_name
The above command unsets the value of a defined variable. Here is a
simple example that demonstrates how the command works −
#!/bin/sh
NAME="Zara Ali"
unset NAME
echo $NAME
In our case we can use:
$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
───────────────────────────────────────────────────────────────────────────────────────────
$ unset JAVA_HOME
───────────────────────────────────────────────────────────────────────────────────────────
$ echo $JAVA_HOME
───────────────────────────────────────────────────────────────────────────────────────────
$
$JAVA_HOME
in more than one place. What does it read when you typeecho $JAVA_HOME
?