How do you change the default TERM value set at console login (Ubuntu)?

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.

A lot of good info here:

man 7 term

A default TERM value will be set on a per-line basis by either /etc/inittab (Linux and System-V-like UNIXes) or /etc/ttys (BSD UNIXes). This will nearly always suffice for workstation and microcomputer consoles.

The next problem is that Ubuntu 9.10 does not have /etc/inittab or /etc/ttys.

man inittab

The Upstart init(8) daemon does not use this file, and instead reads its configuration from files in /etc/init. See init(5) for more details.

Looking into /etc/init, you can find the tty*.conf files. They are run by exec'ing getty. So then:

man getty

term The value to be used for the TERM environment variable. This overrides whatever init(8) may have set, and is inherited by login and the shell.

This is good info. Now we know that the default TERM value comes from init(8)

... after all this I didn't manage to figure out how to change the default TERM value used by init.