If you’ve ever encountered the error message “manpath: can’t set the locale; make sure $LC_ and $LANG are correct”* while using your Linux system, you’re not alone. This common issue typically occurs due to misconfigured or missing locale settings in your environment. The good news is, it’s usually easy to fix — and in this guide, we’ll walk you through everything step-by-step.
What Does This Error Mean?
Before diving into solutions, let’s break down what this error is all about.
Linux uses locales to set language and regional settings, including dates, times, currency, and more formats. When these environment variables aren’t set properly or are missing, Linux can’t determine how to display text correctly, especially in tools like man (manual pages). That’s when you get the “manpath: can’t set the locale” error.
This error doesn’t usually prevent you from running commands, but it can be annoying and may interfere with proper text rendering or command outputs.
Common Causes of the Locale Error
There are a few main reasons this issue might occur:
- Locale settings are missing in your profile or bash configuration files.
- You’re using a minimal Linux installation without full language support.
- Locale data was not generated or installed correctly.
- You’re connecting via SSH from a system that passes invalid locale variables.
Understanding the cause will help you apply the correct fix.
Step-by-Step Guide to Fix the Locale Error on Linux
Depending on your Linux distribution and setup, here are several ways to resolve the problem.
1. Check Current Locale Settings
Start by checking your current locale settings:
localeIf you see output with empty values or errors like “cannot set LC_* to default locale,” it confirms that the issue is with your locale settings.
2. Reconfigure Locales (Debian/Ubuntu Based Systems)
If you’re on Debian, Ubuntu, or a derivative (like Linux Mint), the fastest fix is to reconfigure your locales:
sudo dpkg-reconfigure localesThis command will open a menu. Select your preferred locale (for example, en_US.UTF-8) and press OK. Then, set it as the default.
You can also generate a specific locale manually:
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8Reboot your terminal or restart the system if needed.
3. Set Locale Variables in Shell Configuration
Sometimes, the issue is simply that the variables are not set in your shell’s configuration files. You can manually add them.
Open your ~/.bashrc or ~/.profile file using a text editor:
nano ~/.bashrcThen, add these lines at the end:
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
export LC_ALL=en_US.UTF-8Save and exit, then reload the configuration:
source ~/.bashrcThis sets the environment variables every time you log in or open a new shell.
4. Install Missing Locale Packages (Red Hat/CentOS/Fedora)
On Red Hat-based systems, you might need to install the glibc-langpack for your locale:
sudo dnf install glibc-langpack-enOr on older systems using yum:
sudo yum install glibc-commonThen, set your locale:
localedef -i en_US -f UTF-8 en_US.UTF-8
export LANG=en_US.UTF-8You may also want to add those exports to your shell config file, as shown earlier.
5. Prevent SSH From Passing Invalid Locale Variables
If you connect to your Linux system over SSH from macOS or another Linux system, it might pass incorrect locale values.
To prevent this, edit your SSH config file on the client (your local machine):
nano ~/.ssh/configAdd this line:
SendEnv LANG LC_*Make sure your remote server has AcceptEnv enabled in /etc/ssh/sshd_config.
Then, restart the SSH service on the remote server:
sudo systemctl restart sshdAlternatively, unset problematic variables before connecting:
unset LC_ALL
unset LANG
ssh user@remotehost6. Verify the Fix
Once you’ve applied the changes, open a new terminal window or log out and back in. Run:
localeYou should now see your variables appropriately set, like:
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8
The error message should be gone, and man pages or other applications should work without any locale issues.
Final Thoughts
The “manpath: can’t set the locale” error might initially seem intimidating, but it’s usually nothing more than a misconfiguration. Whether you’re using Ubuntu, CentOS, Debian, or any other Linux distro, following these steps will help you fix the issue and restore normal behavior to your terminal environment.
Properly configured locales prevent errors and ensure that your system displays text and messages correctly, which is essential for a smooth user experience.
By taking a few minutes to adjust your locale settings, you can eliminate this annoying message and keep your Linux system running smoothly.
