Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

bash: warning: setlocale: LC_CTYPE: cannot change locale

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
mateusz.burger
Posts: 37
Joined: 2009-04-03 17:21

bash: warning: setlocale: LC_CTYPE: cannot change locale

#1 Post by mateusz.burger »

Hello everyone,

the issue is simple, as stated in the subject, I do get that warning from the bash for example using the bash_completion.
Other users (tested with a new user, root etc) do not have this problem.

The issue presented itself after i removed all the locales but the EN_US and EN_GB
becuase for an obscure reason I had a system half in english half in spanish and half italian...
it seemd a good reason to get rid of all the locales that I do not wish to use and set everything in EN.

I followed the following guides to set the proper locale with no success:
Debian wiki

Here below you can find some more details:

Warning message

Code: Select all

loco@debian-loco:~$ scp bash: warning: setlocale: LC_CTYPE: cannot change locale (it_IT.UTF-8)
bash: warning: setlocale: LC_CTYPE: cannot change locale (it_IT.UTF-8)
locale -a

Code: Select all

loco@debian-loco:~$ locale -a
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_COLLATE to default locale: No such file or directory
C
C.UTF-8
POSIX
en_GB
en_GB.iso88591
en_GB.iso885915
en_GB.utf8
en_US
en_US.iso88591
en_US.iso885915
en_US.utf8
cat .bashrc

Code: Select all

loco@debian-loco:~$ cat .bashrc 
# System-wide .bashrc file for interactive bash(1) shells.

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, overwrite the one in /etc/profile)
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
#    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
#    ;;
#*)
#    ;;
#esac

# enable bash completion in interactive shells
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
        function command_not_found_handle {
                # check because c-n-f could've been removed in the meantime
                if [ -x /usr/lib/command-not-found ]; then
                   /usr/bin/python /usr/lib/command-not-found -- "$1"
                   return $?
                elif [ -x /usr/share/command-not-found/command-not-found ]; then
                   /usr/bin/python /usr/share/command-not-found/command-not-found -- "$1"
                   return $?
                else
                   printf "%s: command not found\n" "$1" >&2
                   return 127
                fi
        }
fi

# locale -a

Code: Select all

root@debian-loco:/home/loco# locale -a
C
C.UTF-8
en_GB
en_GB.iso88591
en_GB.iso885915
en_GB.utf8
en_US
en_US.iso88591
en_US.iso885915
en_US.utf8
POSIX
# cat /etc/profile

Code: Select all

root@debian-loco:/home/loco# cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

# bash auto completion

if [ -f /etc/bash_completion ]; then
 . /etc/bash_completion
fi

export LANG=en_GB.UTF-8 <<<<======== NO CHANGES EVEN WITH THIS ADDED
This is interesing

Code: Select all

loco@debian-loco:~$ printenv 
GS_LIB=/home/loco/.fonts
KDE_FULL_SESSION=true
[b]LANG=it_IT.UTF-8[/b]
PROFILEHOME=
DISPLAY=:0
SHELL_SESSION_ID=2fe4f1914e1a43c0bd665d1cc5a04c1d
COLORTERM=truecolor
XDG_VTNR=7
PAM_KWALLET5_LOGIN=/tmp/kwallet5_loco.socket
SSH_AUTH_SOCK=/tmp/ssh-IzuFp2haBSN3/agent.1745
XDG_SESSION_ID=3
USER=loco
DESKTOP_SESSION=/usr/share/xsessions/plasma
PWD=/home/loco
HOME=/home/loco
SSH_AGENT_PID=1811
QT_ACCESSIBILITY=1
XCURSOR_SIZE=0
XDG_SESSION_TYPE=x11
MATHEMATICA_HOME=/opt/Wolfram/Mathematica/10.0
XDG_DATA_DIRS=/usr/share:/usr/share:/usr/local/share
KONSOLE_DBUS_SESSION=/Sessions/1
XDG_SESSION_DESKTOP=KDE
GTK_MODULES=gail:atk-bridge
[b]LC_TYPE=en_GB.UTF-8[/b]
TERM=xterm-256color
SHELL=/bin/bash
KONSOLE_DBUS_SERVICE=:1.29
XDG_SESSION_CLASS=user
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XCURSOR_THEME=breeze_cursors
XDG_CURRENT_DESKTOP=KDE
GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
KONSOLE_PROFILE_NAME=Shell
SHLVL=1
XDG_SEAT=seat0
COLORFGBG=15;0
[b]LANGUAGE=en_GB:it:es:pl[/b]
WINDOWID=12582934
QT_QPA_PLATFORM=xcb
LOGNAME=loco
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
XDG_RUNTIME_DIR=/run/user/1000
XAUTHORITY=/home/loco/.Xauthority
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session1
QT_AUTO_SCREEN_SCALE_FACTOR=0
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
KDE_SESSION_UID=1000
KDE_SESSION_VERSION=5
XDG_SESSION_COOKIE=0e549f440fd86c38ff29d965520c33e3-1538652976.158019-1308509184
SESSION_MANAGER=local/debian-loco:@/tmp/.ICE-unix/1939,unix/debian-loco:/tmp/.ICE-unix/1939
_=/usr/bin/printenv
OLDPWD=/home/loco
Why DAFK do I still have the enviromental variables set to IT? This is driving me nuts

One more thing to add, in KDE the language is set to British English, but the region (under format) is set to Italy,
as I want to use all the date, mesaure, currency etc to be set in this region. (This to my understanding should not mess with the locale?)

Many thanks for the help.

mateusz.burger
Posts: 37
Joined: 2009-04-03 17:21

Re: bash: warning: setlocale: LC_CTYPE: cannot change locale

#2 Post by mateusz.burger »

UPDATE: Setting the locale via localectl apparently does not change the local variable...why?

Code: Select all

loco@debian-loco:~$ localectl set-locale LANG=en_GB.UTF-8 LANGUAGE="en_GB:en"
loco@debian-loco:~$ localectl 
   System Locale: LANG=en_GB.UTF-8
                  LANGUAGE=en_GB:en
       VC Keymap: n/a
      X11 Layout: gb
       X11 Model: macbook79
     X11 Options: grp:alt_shift_toggle,lv3:ralt_switch,compose:caps,terminate:ctrl_alt_bksp,grp_led:scroll
loco@debian-loco:~$ printenv | grep UTF
LANG=it_IT.UTF-8
LC_TYPE=en_GB.UTF-8


User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: bash: warning: setlocale: LC_CTYPE: cannot change locale

#3 Post by Head_on_a_Stick »

mateusz.burger wrote:i removed all the locales but the EN_US and EN_GB
lolwut?

Put them back and configure the locale as per the wiki instructions.

Code: Select all

# aptitude reinstall locales
# dpkg-reconfigure locales
deadbang

mateusz.burger
Posts: 37
Joined: 2009-04-03 17:21

Re: bash: warning: setlocale: LC_CTYPE: cannot change locale

#4 Post by mateusz.burger »

LOL :D

I did that thousand times! I wrote it on the original post...obviously no one read it
The only locale I need is for the ENGLISH, I removed all the previous ones (Italian, Spanish, Polish).
Did you see the output of the variables on my previous post?
The issue I think is that some how my LANG var is getting sourced from somewhere else

Code: Select all

loco@debian-loco:~$ localectl set-locale LANG=en_GB.UTF-8 LANGUAGE="en_GB:en"
loco@debian-loco:~$ localectl
   System Locale: LANG=en_GB.UTF-8
                  LANGUAGE=en_GB:en
       VC Keymap: n/a
      X11 Layout: gb
       X11 Model: macbook79
     X11 Options: grp:alt_shift_toggle,lv3:ralt_switch,compose:caps,terminate:ctrl_alt_bksp,grp_led:scroll
loco@debian-loco:~$ printenv | grep UTF
LANG=it_IT.UTF-8 <<<<<<<<<<<<< WHY??!!
LC_TYPE=en_GB.UTF-8

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: bash: warning: setlocale: LC_CTYPE: cannot change locale

#5 Post by bw123 »

found this searching for "Cannot set LC_CTYPE to default locale: No such file or directory" on the internets.
https://askubuntu.com/questions/599808/ ... -directory
mateusz.burger wrote:
the issue is simple, as stated in the subject, I do get that warning from the bash for example using the bash_completion. Other users (tested with a new user, root etc) do not have this problem.
well, did you grep the home folder for the it_ string or the word LANG?

Look like it's another one of those threads, "Here's the error, tell me what I did to get it like this." Do you not recall setting italian at anytime, anywhere, at anyplace? how about an italian server you logged into?
resigned by AI ChatGPT

Post Reply