Search code examples
linuxubuntulocale

Changing locale in Ubuntu 15.04 VPS is not being saved


I just bought a VPS and I'm playing it it using SSH. After a few software packages installations I saw that I had a problem with locales (I need to have en_US.UTF-8 but I have Latin1. I googled it but even after I think I've changed locales then they keep returning to the original ones and I still get problems with software installation. So, I get:

root@myname:~# 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=pt_PT.UTF-8
LANGUAGE=
LC_CTYPE="pt_PT.UTF-8"
LC_NUMERIC="pt_PT.UTF-8"
LC_TIME="pt_PT.UTF-8"
LC_COLLATE="pt_PT.UTF-8"
LC_MONETARY="pt_PT.UTF-8"
LC_MESSAGES="pt_PT.UTF-8"
LC_PAPER="pt_PT.UTF-8"
LC_NAME="pt_PT.UTF-8"
LC_ADDRESS="pt_PT.UTF-8"
LC_TELEPHONE="pt_PT.UTF-8"
LC_MEASUREMENT="pt_PT.UTF-8"
LC_IDENTIFICATION="pt_PT.UTF-8"
LC_ALL=

But before, I have done:

locale-gen en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
export LS_ALL=en_US.UTF-8

So, I can I solve this forever?

PS: I'm doing all this using SSH.


Solution

  • That's because my locale in my local machine is set to Portuguese, which SSH forwards to and tries to use on the server, but the server does not have it installed. I could have stopped forwarding the locale environment variable from my local machine to the server. To do that I would have commented the SendEnv LANG LC_* line in the local /etc/ssh/ssh_config file. Instead I decided to: 1) Generate the locale - Generate the English locale on the server with sudo locale-gen en_US.UTF-8 2) Stop accepting locale environment variable from my local machine to the server. To do that I commented the AcceptEnv LANG LC_* line in the remote /etc/ssh/sshd_config file. Note that for this I had to install the nano package to edit the file (after sudo apt-get install nano I just did nano filename when I was in the file directory). 3) Set the server locale to English - by adding the following lines to my remote ~/.bashrc or ~/.profile files using nano filename again (don't forget they are hidden files inside your home directory so they won't appear in a simple ls search; you need to use ls -la command):

    export LANGUAGE="en"
    export LANG="C"
    export LC_MESSAGES="C"
    export LANG=en_US.UTF-8
    export LANGUAGE=en_US:en
    export LS_ALL=en_US.UTF-8
    

    I also restarted the VM and before that I closed my SSH session and reenter to see if changes were working.