4

When running command in shell (e.g. sudo apt-get install aptitude) this is the output:

dpkg: warning: 'ldconfig' not found in PATH or not executable.
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable.
dpkg: 2 expected program(s) not found in PATH or not executable.
NB: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin.

This are the variables I've set:

export PATH=$PATH:/usr/local/sbin:/usr/local/bin in bashrc
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" in /etc/environment
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" in /etc/sudoerds
echo $path /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/node/node:/usr/local/sbin:/usr/local/bin
sudo echo $path
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/node/node:/usr/local/sbin:/usr/local/bin
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • 2
    I'm voting to close this question as off-topic because it's not a programming question. I suggest deleting it here and reposting in [ubuntu.se]. Also, please update the question to make it clear what you're asking. I don't see an actual *question* in your post. (`sudo sh -c 'echo $PATH'` will show you root's path when running commands under `sudo`.) – Keith Thompson Jan 16 '18 at 19:57
  • Just in case you stepped over this question because `unattended-upgrades` throws such an error ... this is probably due to the default PATH set by crontab. The solution for cron jobs is here: https://stackoverflow.com/questions/2388087/how-to-get-cron-to-call-in-the-correct-paths – BurninLeo Jan 14 '21 at 20:25

3 Answers3

9

Thanks, this worked for me!

nano /root/.bashrc

Go to the very last and enter:

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

After updating the bashrc do:

. /root/.bashrc

OR source /root/.bashrc

Vikram Bankar
  • 386
  • 4
  • 4
3

Try sudo su - and run the same command directly from the root and see if its goes through.

Also set the PATH variable in /root/.bashrc file to be on safer side if it doesn't work.

/root/.bashrc export PATH=/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

This is just environment variable issue unless those binary's are actually missing which is unlikely, you never know others environment :)

1

I stumbled here for a similar case. So I'll add this answer in case someone benefits.

I was receiving this error after a Debian upgrade, from 8 to 9.9. I was installing docker using sudo apt-get install... and got the following error

dpkg: warning: 'ldconfig' not found in PATH or not executable
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
dpkg: error: 2 expected programs not found in PATH or not executable
Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin
E: Sub-process /usr/bin/dpkg returned an error code (2)

I fixed it by editing the file /etc/profile, the following part, from

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi

to

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"
fi

Changes the else part which corresponds to the PATH variable of other users beside root, adds the missing paths.

Original Source (in spanish )

Ernest
  • 962
  • 3
  • 12
  • 28