Wednesday, April 2, 2025

How to fix bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF-8): No such file or directory

 It is a very common error faced on Arch Linx , here are easy steps to fix it 

Check Available Locales

locale -a

Generate the Locale

  • Edit /etc/locale.gen:

    sudo geany /etc/locale.gen
  • Uncomment the line:

    en_US.UTF-8 UTF-8
  • Save the file and run command

    sudo locale-gen

3. Set System-Wide Locale

  • Edit /etc/locale.conf:

    sudo geany /etc/locale.conf

  • Add the following (adjust if needed):

    LANG=en_US.UTF-8
    LC_COLLATE=en_US.UTF-8
    LC_CTYPE=en_US.UTF-8
    LC_ALL=en_US.UTF-8
  • Save the file.


4. Check User-Specific Configuration

Ensure no conflicting locale settings exist in your shell config files (e.g., ~/.bashrc, ~/.bash_profile, ~/.profile). Remove or comment out lines like:

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

5. Apply Changes

  • Log out and log back in, or reboot:

    reboot
     
    Example .profile file  

    # ~/.profile: Executed by Bourne-compatible login shells

    # Add user-specific binaries to PATH
    if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
    fi

    # Set default editor (change to your preference)
    export QT_QPA_PLATFORMTHEME=qt5ct
    export EDITOR=geany
    export BROWSER=firefox
    export VISUAL=nano

    # Set pager with colors
    export PAGER="less -R"

    # For Xorg: Start your window manager/DE from login shell
    if [ -z "$DISPLAY" ] && [ "$(tty)" = "/dev/tty1" ]; then
        exec startx
    fi

    # Source bashrc if using bash (optional)
    # [ -n "$BASH_VERSION" ] && . "$HOME/.bashrc"

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

    set its permissions to 

    chmod 644 ~/.profile  # -rw-r--r-- in linux terminal 




No comments: