Consider, academically, that I have executed sudo mv /bin /foo. I didn't stop to ask questions, I took charge of my destiny and did it.

What would I have to do if I wanted to permanently change the system-wide $PATH to reflect this change? This includes:

  • interactive shells
  • non-interactive shells
  • GUI logins
  • system services
  • sudo use

The reason I ask this, is the water is very muddy about the correct way to do this. Answers to this question variously suggest:

  • editing ~/.bashrc (won't affect e.g. bash --norc)
  • editing ~/.profile (only affects login shells)
  • editing /etc/environment (doesn't affect sudo; sometimes PATH doesn't seem to be here?)

Are there other core system utilities which are likely to cause problems by trying to use some $PATH copy defined in yet other ways or places that I haven't covered here? How do you override $PATH when using sudo?

Where does the One $PATH To Rule Them All live, and how do I add /foo to it?

I know this has been asked a bunch of times but there are so many different questions and answers floating around and many of them are out of date or cover only certain cases.

  • 1
    Editing /etc/environment does change PATH permanently and systemwide; however sudo is configured to use its own secure_path which is unaffected by the PATH variable. May 5, 2019 at 0:52
  • 2
    Does this answer your question? How to add a directory to the PATH? See ish's answer
    – Kulfy
    Nov 18, 2020 at 14:16

2 Answers 2


You probably cannot remove /bin permanently from $PATH because too many scripts will reset it, but you can do some things:

Move /bin to /foo and then symlink /foo to /bin:

Run the following as root:

cd /; mv bin foo; ln -s foo bin

(This begs the question however, if you are so intent upon having contents of /bin in /foo, why not just symlink /bin to /foo?)

Then you can set your custom PATH in /etc/rc.local. That will get sourced at boot regardless of whether anyone is logged in. You will need to create the file if it doesn't exist. Systemd should pick it up. man systemd-rc-local-generator for more info.

  • I picked it as an extreme example of a configuration change that would absolutely require a properly updated $PATH, no compromise would be good enough. Also, looking at that man page, it states that that generator is provided only out of compatibility for system V and its use is discouraged, and furthermore that it runs at the end of the boot process and concurrently with many other systemd targets; I don't see how setting $PATH here would have a systemwide effect.
    – Wug
    May 4, 2019 at 23:27
  • I think if you wanted to completely eliminate /bin you would almost have to rebuild your own distro and literally repackage many core packages. Look at how many times PATH and /bin occur here: grep -r PATH /etc/init.d |grep bin This post has more info about the role of rc.local with systemd: unix.stackexchange.com/a/479766
    – Felicia
    May 6, 2019 at 0:19

I would say editing /etc/environment is the best "system-wide" option.

However, sudo uses a secure path, defined in: /etc/sudoers

So I would say editing these 2 (or only one of them) would be the best way for systemwide path change.

Other environment variables (for instance JAVA_HOME) can also be set in /etc/environment.

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.