61

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

5 Answers 5

71

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 ...
6
  • 1
    I have tried using root user but didn't work.I have checked path too.
    – user87142
    Oct 8, 2014 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. Oct 8, 2014 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, 2014 at 11:52
  • Did you find any solution of it? Jul 20, 2016 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. Feb 16, 2018 at 2:08
10

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!

1
6

The lack of description in the question makes it hard to pinpoint the exact problem in this situation, but I recently faced the same issue:

user@debian:su
Password: 
root@debian:/home/user/Downloads# dpkg -i [Some package]
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

The solution was to use su - instead of su (which is generally better, as detailed in the answers to this question):

user@debian:su -
Password: 
root@debian:~# cd /home/user/Downloads/
root@debian:/home/user/Downloads# dpkg -i [Some package]
2
  • 1
    Great, worked for me! I still have a habit to write su root
    – dompie
    Oct 12, 2020 at 11:06
  • 1
    @dompie I'm sticking to su - since, and prefer it. It's a bit tricky to get used to it, but it's definitely better on the long run, in my opinion.
    – Clément
    Oct 14, 2020 at 8:02
1

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.

1
  • This resolved it for me on Ubuntu 18.04.1
    – sw00
    Mar 22, 2019 at 8:52
0

None of the solutions showed here helped me, so I'll explain what happened to me and what I did to fix it:

I was trying to install Insync in my Q4OS System and I wasn't able because the app requires libc6 >= 2.32 and the Q4OS uses 2.31. I found a libc6 deb of 2.32 and then the nightmare started. It has been broken my entire system. apt-get stopped to work and it says the system needs libc6 2.31 to work properly. At that time I didn't know how to downgrade the version. So, after a restart, the system simply didn't start and hung up with the message on boot:

A start job is running for Hold until boot process finishes up (Xmin Xs/no limit)

I tried to change the terminal without success. Hopefully my Linux was running under the VMWare and I was able to connect in the machine using the SSH. VM -> SSH -> Connect to SSH...

After that, I tried a lot of stuff without success. I tried to upgrade with:

sudo apt install upgrade

and the message says I had to run:

sudo apt --fix-broken install

But when I tried to run that, it said a lot of packages would be removed, including q4os-desktop itself. Well, I accept the conditions and tried. What more could I lost?

After that, the thing gets too worse. I wasn't able to run anything. I got a similar error of the question:

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)

But the problem wasn't the PATH itself but the ldconfig is part of libc6 and it was removed. I couldn't do anything because almost everything depends of libc6 and ldconfig. I tried to compile libc6 from source, but without success. It has a lot of dependencies and when I tried to install a dependency, the lib tried to use something of libc6. A kind of dependency loop.

So, I reboot the system with the Q4OS live CD and just copy the binary ldconfig to /usr/sbin/ldconfig. Fine! Now, the apt-get started to work again (not perfectly, but...). So I discovered how to downgrade the lib:

sudo apt install libc6=2.31-13+deb11u3

If you are not sure which version to use, run:

apt list --installed | grep libc6

inside the Live CD. The output should be something like:

libc6/stable,now 2.31-13+deb11u3 amd64 [installed]

After that, I was able to install the Q4OS again:

sudo apt install q4os-desktop

After a reboot, everything was back to normal!

But now when I run the Insync, the app crashes after 5 seconds.

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