How to change the default TERM value set at console login (Ubuntu)

bashconsoleshellxterm

The $TERM shell value in Ubuntu defaults to "xterm" for a console login. How can I change it so it defaults to "xterm-color"? I'm asking because it looks like this is the easiest way to turn-on the color prompt.

I am aware you can reset the TERM value in the .bashrc or other login script, but I'd rather just force the TERM value to a more reasonable default.

Best Answer

The TERM variable stores the name of an entry in the terminfo database that helps the OS determine how to display information to your terminal. What it defaults to depends entirely on how you've logged in.


Usually, "the console" means you're physically at the computer, logging into one of the text-based virtual terminals (VT1-6).

  • TERM defaults to linux (this may differ between distributions; vt100 is a safe alternative)

    • To change this, on Ubuntu 9.10, you'll need to tweak the getty command defined in /etc/init/tty1.conf. That will change the setting for /dev/tty1 (VT1), and you'll need to make the same changes in /etc/init/tty2.conf, ..tty3.conf, etc to get the other virtual terminals as well.

      # original getty command in /etc/init/tty1.conf
      exec /sbin/getty -8 38400 tty1
      
      # new command; sets default TERM on /dev/tty1 to "foobar"
      exec /sbin/getty -8 38400 tty1 foobar
      

If you're logged into X/Gnome/KDE (VT7, 8, or 9), you're not using a console, at least in this context. Technically this is logging into X and using a pseudo-terminal via a terminal emulator application -- that's what gives you the window that shows your shell & commandline.

  • TERM is initially set by your terminal emulator. It can be modified in your shell startup files (~/.bashrc, ~/.profile, etc).

    • xterm, rxvt, xterm-color, xterm-256color are all common values

    • To change this value, consult the documentation for your terminal emulator. For example, if using rxvt-unicode (aka urxvt), you'd use the -tn termname commandline option.


If you're logged in remotely (via SSH or remote X), you're definitely not using a console in any context; again, you're using a pseudo-terminal.

  • TERM is inherited by the program that started SSH:
    • SSH from a linux virtual terminal results in a remote TERM of linux;
    • SSH from a commandline in an X-windows terminal emulator results in a remote TERM of whatever TERM was set to prior to the SSH command;
    • SSH from a Windows system using PuTTY defaults to xterm, but this can be changed in PuTTY's configuration;
    • and any of the above settings can be overridden by the shell startup files of the remote user.
Related Question