Linux set locale console

How to set locale in the current terminal’s session?

I’m trying to change encoding in the urxvt current session by changing LANG variable. Howerever, it seems like it doesn’t apply immediately. Here is what I do: Available locales:

$ locale -a C en_US.utf8 POSIX ru_RU.koi8r ru_RU.utf8 
$ echo "а" | od -t x1 0000000 d0 b0 0a # good! UTF-8 # | a ||NL| 
$ export LANG=ru_RU.KOI8-R $ echo "а" | od -t x1 0000000 d0 b0 0a # hm..expect 'c1 0a' 
$ echo "а" | od -t x1 0000000 c1 0a 

Which startup files are read by urxvt , add the line with changing locale there. It should reflect it for all your subsequent sessions.

Probably it uses bash. add the line with changing locale there — the problem is not about changing locale at all, but changing it in the CURRENT session. I know I can put this line at .bash_profile or .bashrc — but this is not what I want.

1 Answer 1

  • you may be using a shell with a built-in echo (and have not informed the shell that you are changing the locale)
  • LANG is not the first environment variable checked. According to locale(7) , LC_ALL and LC_CTYPE would be checked first:
If the second argument to setlocale(3) is an empty string, "", for the default locale, it is determined using the following steps: 1. If there is a non-null environment variable LC_ALL, the value of LC_ALL is used. 2. If an environment variable with the same name as one of the categories above exists and is non-null, its value is used for that category. 3. If there is a non-null environment variable LANG, the value of LANG is used.

For the latter, look at the output from the locale command, which lists all of the environment variables which would be used:

$ export LANG=ru_RU.KOI8-R $ locale LANG=ru_RU.KOI8-R LANGUAGE= 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=en_US.UTF-8 

Just changing LANG should not change the other variables, but changing LC_ALL generally does that.

$ export LC_ALL=ru_RU.KOI8-R $ locale LANG=ru_RU.KOI8-R LANGUAGE= LC_CTYPE="ru_RU.KOI8-R" LC_NUMERIC="ru_RU.KOI8-R" LC_TIME="ru_RU.KOI8-R" LC_COLLATE="ru_RU.KOI8-R" LC_MONETARY="ru_RU.KOI8-R" LC_MESSAGES="ru_RU.KOI8-R" LC_PAPER="ru_RU.KOI8-R" LC_NAME="ru_RU.KOI8-R" LC_ADDRESS="ru_RU.KOI8-R" LC_TELEPHONE="ru_RU.KOI8-R" LC_MEASUREMENT="ru_RU.KOI8-R" LC_IDENTIFICATION="ru_RU.KOI8-R" LC_ALL=ru_RU.KOI8-R 

Источник

How to Change or Set System Locales in Linux

A locale is a set of environmental variables that defines the language, country, and character encoding settings (or any other special variant preferences) for your applications and shell session on a Linux system. These environmental variables are used by system libraries and locale-aware applications on the system.

Читайте также:  Удаление пакетов альт линукс

Locale affects things such as the time/date format, the first day of the week, numbers, currency and many other values formatted in accordance with the language or region/country you set on a Linux system.

In this article, we will show how to view your currently installed system locale and how to set system’s locale in Linux.

How to View System Locale in Linux

To view information about the current installed locale, use the locale or localectl utility.

$ locale LANG=en_US.UTF-8 LANGUAGE=en_US 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= $ localectl status System Locale: LANG=en_US.UTF-8 LANGUAGE=en_US VC Keymap: n/a X11 Layout: us X11 Model: pc105

You can view more information about an environmental variable, for example LC_TIME, which stores the time and date format.

$ locale -k LC_TIME abday="Sun;Mon;Tue;Wed;Thu;Fri;Sat" day="Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday" abmon="Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec" mon="January;February;March;April;May;June;July;August;September;October;November;December" am_pm="AM;PM" d_t_fmt="%a %d %b %Y %r %Z" d_fmt="%m/%d/%Y" t_fmt="%r" t_fmt_ampm="%I:%M:%S %p" era= era_year="" era_d_fmt="" alt_digits= era_d_t_fmt="" era_t_fmt="" time-era-num-entries=0 time-era-entries="S" week-ndays=7 week-1stday=19971130 week-1stweek=1 first_weekday=1 first_workday=2 cal_direction=1 timezone="" date_fmt="%a %b %e %H:%M:%S %Z %Y" time-codeset="UTF-8" alt_mon="January;February;March;April;May;June;July;August;September;October;November;December" ab_alt_mon="Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec"

To display a list of all available locales use the following command.

$ locale -a C C.UTF-8 en_US.utf8 POSIX

How to Set System Locale in Linux

If you want to change or set system local, use the update-locale program. The LANG variable allows you to set the locale for the entire system.

The following command sets LANG to en_IN.UTF-8 and removes definitions for LANGUAGE.

$ sudo update-locale LANG=LANG=en_IN.UTF-8 LANGUAGE OR $ sudo localectl set-locale LANG=en_IN.UTF-8

To configure a specific locale parameter, edit the appropriate variable. For instance.

$ sudo update-locale LC_TIME=en_IN.UTF-8 OR $ sudo localectl set-locale LC_TIME=en_IN.UTF-8

You can find global locale settings in the following files:

  • /etc/default/locale – on Ubuntu/Debian
  • /etc/locale.conf – on CentOS/RHEL

These files can also be edited manually using any of your favorite command line editors such as Vim or Nano, to configure your system locale.

To set a global locale for single user, you can simply open ~/.bash_profile file and add the following lines.

LANG="en_IN.utf8" export LANG

For more information, see the locale, update-locale and localectl man pages.

$ man locale $ man update-locale $ man localectl

That’s all! In this short article, we have explained how to view and set system local in Linux. If you have any questions, use the feedback form below to reach us.

Источник

How to Change System Language (Locale) in Ubuntu and Debian?

Locale settings determine the operating system language and regional settings used in the terminal and in the graphical interface (date and time format, currency symbols, available character sets, etc.). This article will look at how to check or set locale settings on Linux distros (Ubuntu, Debian, Mint, etc.).

Читайте также:  Add windows to linux boot menu

You can list the current locale settings in Ubuntu and Debian using the command:

get locale in ubuntu linux

LANG=en_US.UTF-8
LANGUAGE=
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=

List of available locales on the host:

list available system locales

To display detailed information about the locales installed on the current Linux host:

The C.UTF-8 system locale is always present in this list. Let’s try to add the German locale de_DE.UTF-8.

The list of locales available for installation is listed in the file:

To install the locale you need, run the command:

locale-gen - generate new locale fles

You can also enable locales you need by uncommenting the lines in the file /etc/locale.gen:

/etc/locale.gen

To set the default locale, use the command:

$ sudo update-locale LANG=de_DE.UTF-8
$ sudo localectl set-locale LANG=de_DE.UTF-8

This command will write the following line to the /etc/default/locale:

Reboot the Linux host to apply the new locale settings.

You can set a separate locale for different parts of Linux, for example:

$ sudo update-locale LC_NUMERIC=en_US.UTF-8 LC_TIME=en_US.UTF-8 LC_MONETARY=en_US.UTF-8

If you specify a locale that has not yet been generated, the locale command will return errors:

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=fr_FR.utf8

In some cases, you must first set the required locale:

$sudo apt-get install language-pack-fr

If the locale is not set on Linux and the locale -a command returns only three entries:

    You need to generate new locale settings:

sudo update-locale LANG=de_DE.UTF-8

For easier locale management on Debian and Ubuntu, you can use the dpkg-reconfigure tool.

With the following command you can generate, set, or remove locales on Linux:

$ sudo dpkg-reconfigure locales

The utility provides a simple pseudo-graphical interface. Select the locales to install.

dpkg-reconfigure locales

Then set the default locale (default locale for the system environment).

dpkg-reconfigure set default locale for the system environment

To change the encoding in the console (terminal), run the command:

$ sudo dpkg-reconfigure console-setup

Select UTF-8 encoding for the console, then choose which character set support to add.

dpkg-reconfigure console-setup

These settings are stored in:

$ cat /etc/default/console-setup

Then configure the keyboard:

$ sudo dpkg-reconfigure keyboard-configuration

The default recommended keyboard model is Generic 105-key PC. Then add the keyboard mappings (keymaps) for the desired country.

Keyboard settings are specified in the file:

It remains to set the time zone:

$ sudo dpkg-reconfigure tzdata

You can remove locales you don’t use. The list of installed locales is in /usr/lib/locale/locale-archive.

Читайте также:  Renew ip address in linux

List the locales in the archive:

delete locales in linux with localedef

$ sudo localedef --delete-from-archive en_IN.utf8

Источник

Как изменить региональные настройки (локаль) консоли в Ubuntu и Debian?

Параметры локали (locale) определяет язык операционной системы и региональные настройки (форма даты и времени, денежные символы, доступные наборы символов и т.д.), которые используется в терминале и в графическом интерфейсе. В этой статье мы рассмотрим, как получить или изменить текущие настройки локали в Linux на примере Ubuntu и Debian

Вывести текущие настройки локали в Ubuntu и Debian можно с помощью команды:

команда locale в linux

LANG=en_US.UTF-8 LANGUAGE= 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=

Вывести список доступных локалей на хосте:

список доступных локалей на хосте linux

Чтобы вывести подробную информацию об установленных в системе локалях:

Системная локаль C.UTF-8 в этом списке присутствует всегда. Попробуем добавить русскую локаль ru_RU.UTF-8.

Список локалей, доступных для установки перечислен в файле:

Чтобы установить нужную локаль, выполните команду:

Также вы можете установить нужные локали, просто раскомментировав строки в файле /etc/locale.gen:

/etc/locale.gen

Чтобы задать локаль по-умолчанию, выполните команду:

$ sudo update-locale LANG=ru_RU.UTF-8

$ sudo localectl set-locale LANG=ru_RU.UTF-8

Эта команда запишет следующую строку в файл /etc/default/locale:

Перезагрузите хост Linux, чтобы применить новые настройки локали.

Можно задать отдельную локаль для различных региональных настроек Linux, например:

$ sudo update-locale LC_NUMERIC=en_US.UTF-8 LC_TIME=en_US.UTF-8 LC_MONETARY=en_US.UTF-8

Если вы зададите локаль, которая не сгенерировала, команда locale выведет ошибки:

locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory LANG=fr_FR.utf8

В некоторых случаях нужно сначала установить необходимую локаль:

$ sudo apt-get install language-pack-fr

Если локаль в Linux не задана, и команда locale -a возвращает всего три записи:

  1. Нужно сгенерировать новую локаль $ sudo locale-gen ru_RU.UTF-8
  2. Применить новую локаль: $ sudo update-locale LANG=ru_RU.UTF-8
  3. Перезагрузите хост или откройте новое окно терминала.

Для более простого управления локалями в Debian и Ubuntu вы можете использовать утилиту dpkg-reconfigure.

С помощью следующей команды вы сможете сгенерировать, задать или удалить локали в Linux:

$ sudo dpkg-reconfigure locales

Утилита предоставляет простой псевдографический интерфейс. Выберите локали, которые нужно установить.

dpkg-reconfigure locales управление языками в консоли linux

Затем задайте локаль по умолчанию (default locale for the system environment).

добавить язык в linux

Чтобы изменить кодировку в консоли (терминале), выполните команду:

$ sudo dpkg-reconfigure console-setup

Выберите UTF-8 кодировку для консоли, затем выберите поддержку какого набора символов нужно добавить

добавить поддержку набора символов в linux

Затем настройте клавиатуру:

$ sudo dpkg-reconfigure keyboard-configuration

По умолчанию рекомендуется использовать модель клавиатуры Generic 105-key PC. Затем добавьте раскладку клавиш для нужной страны.

Настройки клавиатуры указываются в файле:

Осталось настроить часовой пояс:

$ sudo dpkg-reconfigure tzdata

Вы можете удалить локали, которые не используете. Список установленных локалей содержится в /usr/lib/locale/locale-archive.

Выведите список локалей в архиве:

localedef ru_ru.utf-8 Настройка русской локализации utf-8 в linux

$ sudo localedef —delete-from-archive en_IN.utf8

Источник

Оцените статью
Adblock
detector