This question already has an answer here:

When I am changing (on my debian box) to the root user with su, apparently the PATH is not correctly set. Some vital directories like usr/local/sbin are missing.

In /etc/profile I have the following lines (apparently standard default stuff not written by me):

if [ "`id -u`" -eq 0]; then
export PATH

In /etc/login.defs I have (also default stuff):

ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Why is my PATH not correctly set when I do su?

marked as duplicate by Yaron, meuh, schily, Thomas, sourcejedi Sep 2 '18 at 20:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Are you running "su" or running "su -". ALWAYS use "su -", never use "su" you miss a load of config. – Owl Apr 9 at 9:00

Modern su no longer resets PATH from the caller when asked to preserve the environment; if you need this to happen execute su --login instead.

From /usr/share/doc/util-linux/NEWS.Debian.gz:

- new 'su' (with no args, i.e. when preserving the environment) also
  preserves PATH and IFS, while old su would always reset PATH and IFS
  even in 'preserve environment' mode.
The first difference is probably the most user visible one. Doing
plain 'su' is a really bad idea for many reasons, so using 'su -' is
strongly recommended to always get a newly set up environment similar
to a normal login. If you want to restore behaviour more similar to
the previous one you can add 'ALWAYS_SET_PATH yes' in /etc/login.defs.
  • 2
    I've just now been bitten by this, after upgrading to debian Buster. This was super helpful. – nyov Feb 24 at 21:54

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