I have used SSH (via putty) to connect to a VPC and then added a folder to my path using:

export PATH=$PATH:/my/directory

This works whilst the session is open, however when I close putty then reestablish the SSH connection the changes to PATH are no longer there.

Any help understanding why this happens would be very much appreciated.


The PATH variable that you set did not persist because, well, setting an environment variable is not a persistent operation; it only applies to the shell you made it in (and possibly its descendant processes). The shell you get after reconnecting is not the same one you had before, it's a brand-new one.

To keep a value of PATH that will be set in each new shell you start, you could add the export PATH=... line to one of your shell's init files; for example ~/.bash_profile if using bash.

The following question has more detailed answers: How do I set a user environment variable? (permanently, not session)

  • That worked, do you want me to delete this question? – Tim Mottram Feb 10 '17 at 15:08
  • Well, I don't know if I would call your question a complete duplicate (you were asking why the setting was not persistent, not how to make it persistent, although it seems natural that you wanted the second). Do as you see fit :) – dhag Feb 10 '17 at 15:22

You can add it in PATH variable in your .bash_profile file (hidden) which can be found in your home folder.

[username@hostname ~]# vi .bash_profile

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