18

I am on an Ubuntu (I think) system. I don't have root, so I can't change the locale. I want to make my default terminal profile use UTF-8 by default. There should be a way to do this, either in the .gconf/apps/gnome-terminal/ directory somewhere, or in a environment variable, or something. However, I can't seem to find it.

Edit with more details:

In a terminal, I have:

grid-unv55$ locale
LANG=en_US.UTF-8
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=
grid-unv55$ gnome-terminal

When try to more a UTF document in that new terminal, I get:

\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd
\noise:bgspeech \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd

Which appears on my screen as dots. (the uffds were a cut and paste. I left the "\noise:bgspeech" in there so you could see that ascii cut and pasted correctly)

6 Answers 6

11

I believe that gnome-terminal will Just Work with UTF-8 is enabled in the shell, so all you need to do is enable that. Put

export LANG=en_US.UTF-8

in ~/.bashrc and there you go.


EDIT:

Okay, so, the answer is currently you can't set this. Gnome Terminal follows the current environment's LANG setting and uses the encoding for that as the default. So you need to get LANG to contain UTF-8 before gnome-terminal is launched. Setting this in ~/.bashrc should do it — you'll just need to log out and log in again.

(Note that it's actually better to put this in ~/.bash_profile so you can override it for subshells, but I'm not sure that bash is necessarily run as a login shell as part of setting up the Gnome environment. That's worth testing....)

15
  • 1
    doesn't appear to work. Mar 8, 2011 at 21:45
  • Hmm. What is $LANG set to by default? Does putting that in your bashrc make it change?
    – mattdm
    Mar 8, 2011 at 22:06
  • C, and putting it in the bashrc made it change. Granted, I didn't log-out and log back in again, but I started a new terminal, and it started with UTF in the LANG (and the locale is set with UTF as well) but the terminal still doesn't show Japanese... Mar 8, 2011 at 22:39
  • 1
    Before, it was only getting set in the shell inside gnome-terminal. Now, it's getting set in the environment under which gnome-terminal itself runs.
    – mattdm
    Mar 9, 2011 at 17:08
  • 2
    Under Ubuntu 10.04, you can set environment variables for the whole session from ~/.profilenot ~/.bashrc, and not ~/.bash_profile either. Mar 9, 2011 at 20:19
9

You can set the locale for gnome-terminal with the following command where Default is the name of the profile.

gconftool --set --type=string /apps/gnome-terminal/profiles/Default/encoding en_US.UTF-8
2
  • This worked for me. But was unnecessary after changing LANG=en_US.UTF-8 in .bashrc and restarting Feb 22, 2015 at 1:42
  • Worked great for me!
    – Josh M.
    Jul 8, 2015 at 2:48
7

I had a similar problem, and when setting LANG in .bash_profile didn't do the trick, I found out that in Gnome, the default locale can be set at the beginning of a session from the GDM login screen. This can be done without root access.

3

I just checked in menu->terminal->set character encoding it is utf-8

The terminal and bash are not the same thing.

I would start by doing cat utf-8-file (cat and bash will pass this file unchanged to the terminal, (well actually to stty, stty will convert newline to carrage return, newline etc.)) if this displays the file properly then gnome-terminal is setup. (This so far is all I have ever done, as I use utf-8 in english; it was already set up in Ubuntu 10.10 and Debian 6 for me). So then just to set up bash etc.

Re-reading ~/.bashrc

If you edit ~/.bashrc you must re-read it . ~/.bashrc (or start a new shell) (dont forget the dot)

1
  • 1
    When I manually change the character encoding to utf-8, that's where I do it, but when I start a new gnome-terminal, even from a terminal that has the correct locale, the encoding is still ascii. I'll add more details to the question. Mar 9, 2011 at 15:45
3

I had an issue just now that I fixed that may be relevant for new-comers with newer versions of GNOME (and gnome-terminal):

For any text encoding you want to use, the shell (e.g. bash) and terminal emulator (e.g. gnome-terminal) must use the same encoding. So e.g. if the shell uses en_US.utf8 and the terminal emulator uses en_US.ISO-8859-1 (a.k.a. latin1), then you will see strange text in your terminal for any program with UTF-8 output.

Now, I am not able to set the encoding upon login, as I've seen suggested would be possible. This might be due to the fact that we have an older version of GDM here at work. This is why I've needed a different solution.

Anyway, GNOME 3 doesn't seem to automatically source .bashrc nor .profile upon login. But it does source .gnomerc, in which you can put environment variables that will be exported to GNOME programs (as far as I can tell).

Putting export LANG="en_US.utf8" in .gnomerc thus starts gnome-terminal using a UTF-8 encoding by default, when a new instance is started. (Change your locale according to your needs.)

Hopefully this has been useful to someone!

-1

As mentioned by other users, tell the shell which encoding you're using with

export LANG=en_US.UTF-8

Put this in .bashrc and gnome-terminal should pick it up on the next login.

Set the encoding for gnome-terminal on the fly: Menubar > Terminal > Set Character Encoding

Set default encoding permanently: gconf-editor > Apps > gnome-terminal > Profiles > Default > encoding > utf-8

2
  • 2
    This isn't quite true. For me, I have a .profile and a .bashrc file. My login shell is bash. gnome-terminal ignores LANG settings in .bashrc if it conflicts with LANG settings in .profile. So, LANG needs to be set in both files.
    – Gary
    Nov 18, 2014 at 2:10
  • Sort of … my understanding is that bash uses .profile for login shells, and .bashrc otherwise. On Linux, new command windows use .bashrc (on Mac, it's .profile). I'm unaware of any circumstances where both would be run automatically, but it is extremely common to put all your configuration into one and then call it from the other. Typically, .bashrc is run from .profile (typically only from interactive shells). if [ -n "$BASH_VERSION" -a -f "$HOME/.bashrc"; then . "$HOME/.bashrc"; fi Apr 20, 2016 at 20:53

You must log in to answer this question.

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