How to Enable or Missing UTF-8 Support in Linux

  • Post last modified:April 27, 2021
  • Reading time:6 mins read

When you access a specific web page or any text file which is written in a different language or use an ASCII message, then your system will not be able to detect language.

Because of that, you will see “X” all over the file. All this happens because of missing UTF-8, or you have selected the wrong locales.

Through this article, we will enable UTF-8 support using the terminal in Linux. Before that, first understand what is UTF-8, Why the system requires UTF-8 support?

Note:- In this article, some of the text will not appear as we intend so that you may see a square box or any other characters.

What is UTF-8?

We live in the 21st century where every information gets transfer in a second over the internet, just like reading this guide. It’s doesn’t matter whether you are in the US or Japan.

Because of vast data reachability, there is a problem of language locale inconsistency.

For example

The actual text is “TrendOceans からのこのガイド” In case of missing UTF-8 support. You will see “X TPՎTrendOceans.”

Now you know why the problem occur and let’s solve this issue.

First of all, open a terminal and type the following command to check whether the locale package is available on your system.

# dpkg -l locales
[email protected]:~# dpkg -l locales

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version       Architecture Description
+++-==============-=============-============-=================================>
ii  locales        2.32-0ubuntu3 all          GNU C Library: National Language >
lines 1-6/6 (END)

If the output is not the same as above, then you need to install the local package.

# apt-get install locales

In the next step, you need to reconfigure the locale package, type the below command, and make sure to run as root.

# dpkg-reconfigure locales

Now you will see the number of locales available to generate the following UTF-8 support. Using the arrow key, navigate up and down to choose en_US-UTF-8 or any other UTF-8 locale.

Package configuration
                   Configuring locales

Locales are a framework to switch between multiple languages and allow users to use their language, country, characters, collation order, etc. 

Please choose which locales to generate. UTF-8 locales should be chosen by default, particularly for new installations. Other character sets may be useful for backwards compatibility with older systems and software.

Locales to be generated: 

[ ] All locales                                       ↑             [ ] aa_DJ ISO-8859-1                                                [ ] aa_DJ.UTF-8 UTF-8                                              [ ] aa_ER UTF-8                                                   
[ ] [email protected] UTF-8  
[ ] **********  UTF-8
[*] en_US.UTF-8 UTF-8     
[ ]  ********** UTF-8                                 ↓

After that, again, it will ask you to select the default locale. On this screen, also select en_US.UTF-8.

 Default locale for the system environment: 

None
C.UTF-8
en_US.UTF-8
******.UTF-8

Now, wait for the Linux System to generate an automated locale according to your selected preference.

[email protected]:~# dpkg-reconfigure locales
Generating locales (this might take a while)...
  ar_AE.UTF-8... done
  ar_BH.UTF-8... done
  ar_DZ.UTF-8... done
  ar_EG.UTF-8... done
  ar_IN.UTF-8... done
  ar_IQ.UTF-8... done
  ar_JO.UTF-8... done
  ar_KW.UTF-8... done
  ar_LB.UTF-8... done
  ar_LY.UTF-8... done
  ar_MA.UTF-8... done
  ar_OM.UTF-8... done
  ar_QA.UTF-8... done
  ar_SA.UTF-8... done
  ar_SD.UTF-8... done
  ar_SS.UTF-8... done
  ar_SY.UTF-8... done
  ar_TN.UTF-8... done
  ar_YE.UTF-8... done
  de_AT.UTF-8... done
  de_BE.UTF-8... done
  de_CH.UTF-8... done
  de_DE.UTF-8... done
  de_IT.UTF-8... done
  de_LI.UTF-8... done
  de_LU.UTF-8... done
  en_AG.UTF-8... done
  en_AU.UTF-8... done
  en_BW.UTF-8... done
  en_CA.UTF-8... done
  en_DK.UTF-8... done
  en_GB.UTF-8... done
  en_HK.UTF-8... done
  en_IE.UTF-8... done
  en_IL.UTF-8... done
  en_IN.UTF-8... done
  en_NG.UTF-8... done
  en_NZ.UTF-8... done
  en_PH.UTF-8... done
  en_SG.UTF-8... done
  en_US.UTF-8... done
  en_ZA.UTF-8... done
  en_ZM.UTF-8... done
  en_ZW.UTF-8... done
  es_AR.UTF-8... done
  es_BO.UTF-8... done
  es_CL.UTF-8... done
  es_CO.UTF-8... done
  es_CR.UTF-8... done
  es_CU.UTF-8... done
  es_DO.UTF-8... done
  es_EC.UTF-8... done
  es_ES.UTF-8... done
  es_GT.UTF-8... done
  es_HN.UTF-8... done
  es_MX.UTF-8... done
  es_NI.UTF-8... done
  es_PA.UTF-8... done
  es_PE.UTF-8... done
  es_PR.UTF-8... done
  es_PY.UTF-8... done
  es_SV.UTF-8... done
  es_US.UTF-8... done
  es_UY.UTF-8... done
  es_VE.UTF-8... done
  fr_BE.UTF-8... done
  fr_CA.UTF-8... done
  fr_CH.UTF-8... done
  fr_FR.UTF-8... done
  fr_LU.UTF-8... done
  it_CH.UTF-8... done
  it_IT.UTF-8... done
  ja_JP.UTF-8... done
  pt_BR.UTF-8... done
  pt_PT.UTF-8... done
  ru_RU.UTF-8... done
  ru_UA.UTF-8... done
  zh_CN.UTF-8... done
  zh_HK.UTF-8... done
  zh_SG.UTF-8... done
  zh_TW.UTF-8... done
Generation complete.

After completing the above process, update the .bashrc file with the following line To open the .bashrc file using the command line editor

#nano .bashrc

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

The Next step is to verify the changes using command locale.

#locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=

To see the changes reboot or log out your system.

I think so you able to change the locale in your Linux system. We have run the steps and commands mentioned in this article on a Ubuntu 20.04 LTS system, but it will also work on other distributions. If you are facing any difficulty to change the locale, then comment to us.

Like what you read? Please share it with others.
  • 1
    Share

Leave a Reply