Broken my Debian install: 'sh' not found in PATH
Solution 1
As stated by @Stephen Kitt I had encountered this bug in dash
which had broken sh
(the Bourne shell) as /bin/sh
is a symlink to /bin/dash/
in my particular distribution.
Running sudo ln -sf bash /bin/sh
in order to point sh
to bash
and then running sudo apt-get update
followed by sudo apt-get install --reinstall dash
followed by sudo apt-get full-upgrade
solved the issue.
Solution 2
You were bitten by a nasty bug in dash
which caused /bin/sh
to be removed. This has since been fixed, which is why another apt update
and apt full-upgrade
fixed it (after restoring /bin/sh
to point to bash
presumably, your comments aren’t clear about that).
Related videos on Youtube
Fearg
Updated on September 18, 2022Comments
-
Fearg over 1 year
I'm running a custom build of
Debian buster/sid
. I have broken a lot of things seemingly by mistakenly runningapt-get dist-upgrade
(I think that's what did it). So the desktop manager\desktop environment no longer loads at all and I just get a command-line shell.Aptitude and apt-get are broken as is dpkg.
apt update, aptitude update and apt-get update fails and gives a lot of errors when attempted to run, however my /etc/apt/sources.list looks fine
deb http://ftp.ie.debian.org/debian unstable main contrib non-free deb-src http://ftp.ie.debian.org/debian unstable main contrib non-free deb http://ftp.ie.debian.org/debian experimental main contrib non-free deb-src http:// ftp.ie.debian.org/debian experimental main contrib non free deb https://dl.winehq.org/wine-builds/debian sid main deb https://dl.winehq.org/wine-builds/ubuntu sid main
errors on update like this:
Err:2 http://ftp.ie.debian.org/debian unstable InRelease Couldn't execute /usr/bin/apt-key to check /var/lib/apt/lists/partial/ftp.ie.debian.org_debian_dists_experimental_InRelease
and
E: Problem executing scripts APT::Update::Post-Invoke-Success '/usr/bin/test -e /usr/share/dbus-1/system-services/org.freedesktop.PackageKit.service && /usr/bin/test -S /var/run/dbus/system_bus_socket && /usr/bin/gdbus call --system --dest org.freedesktop.PackageKit --object-path /org/freedesktop/PackageKit --timeout 4 --method org.freedesktop.PackageKit.StateHasChanged cache-update > /dev/null; /bin/echo > /dev/null' E: Sub-process returned an error code
aptitude upgrade, apt upgrade or apt-get upgrade appear to be broken due to dpkg being broken
Dpkg gives this error:
dpkg: warning: 'sh' not found in PATH or not executable dpkg: error: 1 expected
however
echo $PATH
returns, which looks fine to me/home/ferg/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
if I try
sh
I getThe program 'sh' is currently not installed. To run 'sh' please ask your administrator to install the package 'dash'
If I try
sudo apt-get install dash
it tells me
dash is already the newest version (0.5.8-2.6)
and if I continue
E: Sub-process /usr/sbin/dpkg-preconfigure --apt || true returned an error code (100) E: Failure running script /usr/sbin/dpkg/preconfigure --apt || true
If I run
sudo nano /etc/apt/apt.conf.d/70debconf
and comment out the lineDPkg::Pre-Install-Pkgs {"/usr/sbian/dpkg-preconfigure --apt || true";};
then aptitude fails with
dpkg: warning: 'sh' not found in PATH or not executable dpkg: error: 1 expected
So I can't reinstall necessary packages to restore the system because dpkg (and therefore aptitude, apt-get, apt) are broken, seemingly because sh is not in my PATH. However all the correct directories are in my PATH. I'm assuming that fixing this issue with sh would allow dpkg and aptitude to work again but I'm wondering what precisely is the problem with sh?
Thank you in advance for any help.
Update:
ls -l /bin/bash
returns
-rwxr-xr-x 1 root root 1099016 May 15 2017 /bin/bash
ls -l /bin/sh
returnslrwxrwxrwx 1 root root 4 Jun 28 2017 /bin/sh -> dash
ls -l /bin/dash
returnsls: cannot access 'bin/dash': No such file or directory
So /bin/sh seems to redirect to /bin/dash which has been deleted somehow?
sudo apt-get install --reinstall dash
fails with:1 not fully installed or removed. After this operation, 0 B of additional disk space will be used. E: Internal Error, No file name for dash:amd64
Running
sudo ln -sf bash /bin/sh
and thensudo apt-get install --reinstall dash
fails with the same error as above.Searching for this issue and variants of it on Google I've found numerous solutions related to the user's PATH and permissions, I've checked the files which relate to that including
/etc/sudoers
/root/.bashrc
and/root/.profile
and/etc/profile
. In most of those cases the users were able to solve their issue by simply defining their path correctly (usually the/sbin
or/usr/sbin
directories were missing). As stated above my PATH seems to contain all the relevant directories whether I runecho $PATH
normally or as root orsudo echo $PATH
. Some users were also having issues with permissions or withsudo
itself. I've also tried executing variousaptitude
apt
andapt-get
anddpkg
commands as root usingsudo -i
which suggests that my issue is different. -
LnxSlck over 3 yearsLife saver. I though I had to do a reinstall