I set environment variable using export CATALINA_HOME=/home/chirag/Softwares/apache-tomcat-7.0.56 before some time from the terminal.

But now i want to unset this variable premenantly.

I use unset CATALINA_HOME to remove that variable but when I open other terminal that variable is available with the same value.

How can I remove the 'env variable' permanently ? Thanks in advance.

  • 1
    First you have to figure out where you set that variable in the first place. Do you know where you set it before? Simply setting it in the terminal is not enough to make a 'permanent' env variable – Thomas Ward May 17 '15 at 16:09
  • No I don't know where that variable is set at first time. – Chirag Patel May 17 '15 at 16:14
  • In my home directory I found .bashrc file and line export CATALINA_HOME=/home/chirag/Softwares/apache-tomcat-7.0.56 at the end of the file. So I remove that line ? – Chirag Patel May 17 '15 at 16:32
  • Thanks, I remove line containing CATALINA_HOME variable and it works. – Chirag Patel May 17 '15 at 16:48
  • Glad to hear it! I've moved my comments into an answer so you can accept it as the valid answer and mark the question as 'solved'. – Thomas Ward May 17 '15 at 17:55

The environment variable is always going to be set if it's present in your configuration files for your system's environment variables or your own login profiles.

Open each of these files and search for a line that has export CATALINA_HOME, and remove the line (or comment it out) where present:

  • /etc/environment
  • /etc/profile
  • ~/.profile
  • ~/.bashrc

Once removing the line from the file, log out, and log back in (if in a terminal, just close the terminal and reopen it). If it was in /etc/environment then consider rebooting the system first.

With the export line gone, the variable will be 'permanently unset' until the line is readded to one of those files.

  • 1
    In my case I had to comment out export var in /etc/profile. – Rishabh Agrahari Jul 15 '17 at 3:46
  • JAVA_HOME is in none of these, yet set when I launch a terminal... – Xerus Apr 5 '18 at 23:43
  • @Xerus Sounds like there might be something else called from one of these (check all the included filepaths inside each of these too) which sets JAVA_HOME. You might need your own question for this one, though. – Thomas Ward Apr 6 '18 at 13:26

Just to supplement the existing good answer, here's a simple line to help you to find the file you need to edit, based on this answer:

egrep -lir "export variable" /etc/environment /etc/profile ~/.profile ~/.bashrc

The word enclosed in quotes is the name of the environment variable it will search for.

It will provide you with the filename, then you just need to find the corresponding exprot line and comment or delete it.


add unset CATALINA_HOME to the shell file (.bashrc or .zshrc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.