How to fix dpkg: warning: PATH is not set in APT
The PATH environment variable is not set when running dpkg. This prevents dpkg from finding essential programs like ldconfig and start-stop-daemon, causing installation failures.
Quick fix
Fixes dpkg: warning: PATH is not set
su -- Use 'su -' instead of 'su' to switch to root
- Verify PATH contains system directories
- Manually set PATH if necessary
- Use 'sudo -i' as an alternative to 'su -'
su -dpkg: warning: PATH is not set
What this error means
The dpkg package manager requires the PATH environment variable to locate helper programs needed during package installation and configuration. When PATH is not set or doesn't include critical system directories like /usr/sbin and /sbin, dpkg cannot execute these programs and will fail with a warning or error. This typically happens when using 'su' instead of 'su -' to switch to root, or when running dpkg in a shell with an incomplete environment.
Typical symptoms
- dpkg fails to install or configure packages when run as root
- Error mentions 'ldconfig', 'start-stop-daemon', or 'update-rc.d' not found
- Installation works with sudo but fails with su
- Container or build process fails during package installation
Common causes
- Using 'su' instead of 'su -' when switching to root, leaving user PATH intact
- Running dpkg in a shell environment without proper PATH initialization
- Manually unsetting or incorrectly configuring the PATH environment variable
- Entering a restricted shell or SSH session without a login shell initialization
- Using Docker or containers without proper environment setup
How to fix "dpkg: warning: PATH is not set"
When switching to the root user, always use the dash flag:
su -Instead of just:
suThe dash flag ensures that the root user's full login environment is initialized, including the correct PATH variable containing /usr/sbin, /usr/bin, /sbin, and /bin.
Check if your PATH includes the necessary system directories:
echo $PATHYou should see output similar to:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binIf this is missing or incomplete, proceed to the next step.
If PATH is not set correctly, export the full path before running dpkg:
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binThen run your dpkg command:
dpkg -i package.debIf you prefer not to use 'su -', you can use sudo with the -i flag:
sudo -iThis also loads the target user's login shell and sets up the environment correctly. You can then run dpkg commands without PATH issues.
Advanced notes
Maintainer scripts in Debian packages should not prepend absolute paths to program names like ldconfig or start-stop-daemon. The Debian policy expects these programs to be found via PATH. If you're seeing this in a container, ensure your Dockerfile or build script uses proper shell initialization (e.g., '/bin/bash -l' instead of '/bin/sh'). For WSL users with ldconfig-specific issues, the ldconfig binary is part of the libc-bin package, not a standalone package.
Frequently asked questions
- What does "dpkg: warning: PATH is not set" mean?
- The dpkg package manager requires the PATH environment variable to locate helper programs needed during package installation and configuration. When PATH is not set or doesn't include critical system directories like /usr/sbin and /sbin, dpkg cannot execute these programs and will fail with a warning or error. This typically happens when using 'su' instead of 'su -' to switch to root, or when running dpkg in a shell with an incomplete environment.
- How do I fix "dpkg: warning: PATH is not set"?
- The PATH environment variable is not set when running dpkg. This prevents dpkg from finding essential programs like ldconfig and start-stop-daemon, causing installation failures.
- What causes "dpkg: warning: PATH is not set"?
- Using 'su' instead of 'su -' when switching to root, leaving user PATH intact Running dpkg in a shell environment without proper PATH initialization Manually unsetting or incorrectly configuring the PATH environment variable
- Is the "dpkg: warning: PATH is not set" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.