Fix: Can't exec "locale": No such file or directory at /usr/share/perl5/Debconf/Encoding.pm

Warp Terminal

While running apt-get, you run in to an error that looks like:

Can’t exec “locale”: No such file or directory at /usr/share/perl5/Debconf/Encoding.pm line 16.
Use of uninitialized value $Debconf::Encoding::charmap in scalar chomp at /usr/share/perl5/Debconf/Encoding.pm line 17.
dpkg: warning: ‘ldconfig’ not found in PATH or not executable
dpkg: error: 1 expected program 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)

This is a commonly occurring issue in Debian and Debian based Linux distributions such as Ubuntu and Linux Mint. You’ll stuck this problem and will not be able to update or install new programs.

My friend ran into this problem while running an older version of Ubuntu but the solution presented here should be applicable to newer versions as well. In fact, it should work on Mint and other Ubuntu-based distros as well.

Solution

As per this old forum thread, ldconfig perhaps have been moved from libc6 to libc-bin. Here is what you can do to fix this issue.

In a terminal, use the following commands to download and extract the libc-bin package:

apt-get download libc-bin
dpkg -x libc-bin*.deb unpackdir/

Next you need to copy these files:

sudo cp unpackdir/sbin/ldconfig /sbin/

Now you need to make sure that things are in order. Run these commands to ensure that:

sudo apt-get install --reinstall libc-bin
sudo apt-get install -f

Normally, this should fix the problem of Can’t exec “locale”: No such file or directory at /usr/share/perl5/Debconf/Encoding.pm line 16. Do let me know in the comment section whether or not this fixes your problem.

It's FOSS turns 13! 13 years of helping people use Linux ❤️

And we need your help to go on for 13 more years. Support us with a Plus membership and enjoy an ad-free reading experience and get a Linux eBook for free.

To celebrate 13 years of It's FOSS, we have a lifetime membership option with reduced pricing of just $76. This is valid until 25th June only.

If you ever wanted to appreciate our work with Plus membership but didn't like the recurring subscription, this is your chance 😃

Get Lifetime Membership of It's FOSS
About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries 🕵️‍♂️

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.