π ~1 min read
Table of contents
Symptom & Impact
CLI tools and scripts show encoding errors or garbled text output.
Environment & Reproduction
Usually after minimal installs or manual environment variable edits.
locale
python3 -c 'print("test")'
perl -e 'print qq(OKn);'
Root Cause Analysis
Missing generated UTF-8 locale or inconsistent LANG/LC_* variables.
Quick Triage
Inspect active locale settings and generated locale database.
locale
localectl status
locale -a | grep -i utf
Step-by-Step Diagnosis
Confirm default locale files and shell profile overrides.
cat /etc/default/locale
grep -R 'LC_|LANG=' ~/.profile ~/.bashrc /etc/environment -n
locale -a

Solution – Primary Fix
Generate en_US.UTF-8 and set as system default locale.
Still having issues? Our IT Solutions & Services team can diagnose and resolve this for you. Get in touch for a free consultation.
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8
source /etc/default/locale

Solution – Alternative Approaches
Set a different UTF-8 locale aligned with region requirements.
sudo locale-gen en_GB.UTF-8
sudo update-locale LANG=en_GB.UTF-8
Verification & Acceptance Criteria
UTF-8 locale is active and applications run without encoding exceptions.
locale
python3 - <<'PY'
print('UTF-8 OK')
PY
Rollback Plan
Restore previous /etc/default/locale backup if required.
sudo cp /etc/default/locale.bak /etc/default/locale
source /etc/default/locale
Prevention & Hardening
Standardize locale setup in provisioning scripts.
localectl status
locale -a | grep UTF-8
Related Errors & Cross-Refs
Can coincide with terminal font or shell environment misconfiguration.
Related tutorial: View the step-by-step tutorial for Ubuntu 24.04 LTS.
View all Ubuntu 24.04 LTS tutorials on the Tutorials Hub β
Browse all common problems & solutions on the Tutorials Hub.
References & Further Reading
Ubuntu locale and internationalization documentation.
Need Expert Help?
If you cannot resolve this yourself, our team offers hands-on Server Management, Managed IT Services, and flexible Support Plans. Contact us today β we respond within one business day.