2

I want to learn how to add and remove a directory/file from the PATH but there are hundred answers and a lot of them are contradictory (or so I believe).

I have found answers that suggest editing .profile and others that say that this file is no longer supported for this job (or that is what I understand).

I have found answers that suggest editing /etc/environment.

Some other answers suggest editing '~/.bashrc' file.

Also I have found some answers suggesting writing something like export PATH=...

Currently I don't know which of these suggestions are correct, which of them are advisable to be used without causing any side effects in my system and I haven't got any idea hot to remove a directory/file from the PATH.

So how can I add and remove a directory/file from the PATH correctly?

2 Answers 2

2

/etc/profile : A global configuration script that applies to all users.

~/.bash_profile : A user's personal startup file. Can be used to extend or override settings in the global configuration script.

~/.bash_login : If ~/.bash_profile is not found, bash attempts to read this script.

~/.profile --> If neither ~/.bash_profile nor ~/.bash_login is found, bash attempts to read this file. This is the default in Debian-based distributions, such as Ubuntu.

/etc/bash.bashrc : A global configuration script that applies to all users.

~/.bashrc : A user's personal startup file. Can be used to extend or override settings in the global configuration script.

export – Export environment to subsequently executed programs

The /etc/environment file sets the variable system wide for every user on boot.

From the definition above, the criteria of adding and removing a directory/file from the PATH correctly is related to your needs.

1
  • @Adam Welcome friend
    – Maythux
    May 6, 2015 at 5:12
2

/etc/environment is where the default PATH is set. To remove a directory from that, I suppose the easiest way is to edit it directly. OTOH I think you should think twice before doing so.

Otherwise, as has been mentioned in other answers, there are several possible places where you could add a directory. Also, the tutorial EnvironmentVariable provides useful guidance.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .