3

In my ~/.profile, I have:

export LANG=C.UTF-8

I think that was the Ubuntu default.

However, when I start a shell (e.g. Konsole), I get:

gz@gcomputer:~$ echo $LANG
de_DE.UTF-8

Even when I change my ~/.profile to export LANG=en_US.UTF-8, I don't get a difference.

Why? How can I fix this?

5
  • UTF-8 encoding does not make any sense to the C locale. Also the best place to set LANG is /etc/default/locale.
    – heemayl
    Jul 30, 2016 at 17:55
  • Konsole probably starts a non-login bash shell (which would therefore read ~/.bashrc rather than ~/.profile, I think?) Jul 30, 2016 at 19:35
  • @heemayl C.UTF-8 is fairly new but it does make sense. See sourceware.org/glibc/wiki/Proposals/C.UTF-8
    – zwol
    Jul 30, 2016 at 21:19
  • @zwol ahhh.. didn't know about the proposal.. thanks..
    – heemayl
    Jul 30, 2016 at 21:24
  • Possibly there is some syntax error in your ~/.profile which prevents it from being run correctly. You can check that with the command: bash -n ~/.profile Jul 31, 2016 at 20:47

2 Answers 2

4

According to this answer You should change language settings in etc/default/locale and ~/.pam_environment, not in ~/.profile

etc/default/locale is generated by update-locale so you do this to set LANG=en_GB.UTF-8 (the file also sets LANGUAGE)

update-locale LANG=en_GB.UTF-8

In ~/.pam_environment language settings look the same as in /etc/default/locale:

LANGUAGE=en_GB:en
LANG=en_GB.UTF-8

and can be edited as desired. You have to log out and back in or use source:

In general you have to log out and log back in for changes made to ~/.profile to take effect.

However, you can make them instant using source

source ~/.profile

Example:

I edit my ~/.profile to include:

export foo=bar

save and exit...

in a new shell:

$ echo $foo

(nothing)

$ source ~/.profile
$ echo $foo
bar

If nothing changed after logging out and back in, check that ~/.bash_profile and ~/.bash_login do not exist (because, as mentioned by @ByteCommander, if they do exist, ~/.profile is not sourced)

If either do exist, the best thing to do is probably to copy any commands from them into your ~/.profile and rename them something like ~/.bash_profile_old and ~/.bash_login_old, so that ~/.profile gets sourced (and you are not depending on bash being your shell)

If neither of them exist, it may be that ~/.profile is still not getting sourced for some reason:

See Eliah Kagan's answer here for more detail

The suggested workaround is to use... ~/.pam_environment

1
  • # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login exists.
    – Byte Commander
    Jul 30, 2016 at 17:35
1

For reasons too tedious to get into here, bash has several per-user configuration files. The most important two are .profile and .bashrc. Bash reads one or the other of them on every startup, but not both, depending on conditions which are too confusing for me to bother remembering.

What I do instead is put everything meaningful in .profile, plus an extra line reading

profile_loaded=t

and then I have a .bashrc consisting just of

if test -z "$profile_loaded"; then
    . ~/.profile
fi

If you adopt this approach, it is important to make sure that everything .profile does is idempotent, which is a fancy word for "doing this more than once is the same as doing it only once. One easy way to accomplish that is to wrap the entire contents of .profile in a similar conditional:

if test -z "$profile_loaded"; then

    # ... all the actual work goes here ...

    profile_loaded=t
fi

(If you have files named .bash_profile or .bash_login, that confuses the issue further: I strongly recommend copying their contents into .profile, deleting them, and then cleaning up any duplication in .profile.)

3
  • 1
    Please note that ~/.profile is sourced by lightdm on an Ubuntu desktop, so no, I don't think it's a good idea to have everything in ~/.profile. For non-expert users I'd rather say: Stick to the default as far as possible. Jul 30, 2016 at 21:44
  • @GunnarHjalmarsson How can that possibly work? lightdm doesn't contain an entire implementation of Bourne shell language, does it?
    – zwol
    Jul 31, 2016 at 16:44
  • 1
    No, but it makes use of it. Actually, since a couple of years (my fault) it depends on bash. At first hand I'm talking about /usr/sbin/lightdm-session. Jul 31, 2016 at 19:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .