I was trying to install bsd-mailx utility the package got installed however I am wondering about the error.

This is the error I get:

Preconfiguring packages ...
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)
  • Can you post the output of echo $PATH please? – chaos Oct 8 '14 at 11:30
  • @chaos,How to get that? – user87142 Oct 8 '14 at 11:36
  • @user87142 Just type echo $PATH in a terminal. – John WH Smith Oct 8 '14 at 11:38
  • @chaos,I get this .../usr/local/bin:/usr/bin:/bin:/usr/games – user87142 Oct 8 '14 at 11:46
  • And the output of cat /etc/environment? – chaos Oct 8 '14 at 11:48

First of all, the lines you are truly interested in are:

dpkg: warning: 'ldconfig' not found in PATH or not executable.
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable.

These errors have been reported several times by Debian and Ubuntu users (you can actually Google them for more information). It seems like the PATH variable isn't correctly set when the user tries to execute a command through sudo, which is probably what you are trying to do.

Solution 1: Set sudo's default secure path

Open /etc/sudoers by running visudo in your terminal, and make sure the file includes the following line:

Defaults env_reset
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

More information about this problem may be found here (Problems and tips > PATH not set).

Solution 2: use the root account directly

Don't use sudo, just switch to root to run your commands. Run one of the following commands to do so:

$ sudo -i
$ su 

Once you are logged in as root, just run your apt-get commands again:

# apt-get ...

You might have to set root's PATH first though. Edit /root/.bashrc (with root privileges of course), and add the following line:

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

Solution 3: try to pass the PATH variable to sudo at execution time.

Just prefix the sudo call with the redefinition of the PATH variable:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin sudo apt-get ...
  • 1
    I have tried using root user but didn't work.I have checked path too. – user87142 Oct 8 '14 at 11:40
  • @user87142 Well you didn't check correctly, since /sbin is missing. Try setting it up again (solutions 1 and/or 3). I edited solution 2 to include a way to edit root's PATH when using the account interactively. – John WH Smith Oct 8 '14 at 11:48
  • I have checked that......Defaults env_reset Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" – user87142 Oct 8 '14 at 11:52
  • Did you find any solution of it? – Brijesh Valera Jul 20 '16 at 7:10
  • A variation of his 3rd solution is to export PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/bin:/bin first, then sudo -E apt install nginx after that. The -E switch means --preserve-env thus exporting your env vars to the sudo session. – Mark Hudson Feb 16 at 2:08

I had this problem today, and solved it by commenting out the line (using a #)

Defaults    exempt_group=sudo

from my /etc/sudoers file using

# visudo

as root

This change will cause sudo to use the default secure_path variable set in the same file.

somehow I had the same problem.

Please read your error message carefully and you will find the solution. There is a note that says:

Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin.

Then I checked my path and somehow I was missing the /sbin in my path.

echo $PATH

then I added and the problem was gone. :)

export PATH="$PATH:/sbin"

Tcharam!

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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