I have a few questions about the relationship between TERM, terminfo and termcap and Emacs.

  • I do not know exactly what TERM, terminfo and termcap are.

  • I am on OS X. I do not know what values (and where) I should set variables such as TERM.

But since such information is not really about Emacs I will seek it elsewhere.

With respect to Emacs, my question is this: How are such things are used by Emacs by shell and ansi-term?

  • Start with this response: emacs.stackexchange.com/a/242/7045
    – Emacs User
    Commented Aug 31, 2016 at 1:42
  • Another inevitable question answered: emacs.stackexchange.com/a/2743/7045
    – Emacs User
    Commented Aug 31, 2016 at 1:44
  • Thanks @EmacsUser I read through those answers and already knew that info. Commented Aug 31, 2016 at 2:40
  • Only one question per question, please. And it should be about Emacs. I edited your question to the only Emacs question I saw in it. Feel free to edit it further, to better clarify just what you are asking.
    – Drew
    Commented Aug 31, 2016 at 22:24

2 Answers 2


Termcap and terminfo are both methods for an application running in a terminal to obtain information about the terminal — what it can do and how (e.g. its size, how to move the cursor around, etc.). Both consist of a database that associates terminal capability descriptions to terminal names, as well as a library of code to query the database.

The TERM environment variable gives the terminal name, which applications look up in the database. Some applications also support the environment variable TERMCAP which describes the terminal capabilities in termcap format. There is also an environment variable TERMINFO, but it contains the location of the terminal database files, not the actual terminal description.

In general, you should not set TERM. The terminal emulator sets it for you, or the OS configuration for a hardware terminal. Remote login methods (e.g. ssh, telnet) copy the local value of TERM to the remote host, but typically don't propagate TERMCAP or TERMINFO.

Shell mode sets TERM to dumb, a terminal that can basically do nothing other than display output line by line. Term (M-x term or M-x ansi-term) sets TERM to eterm-color (this can be configured by setting the variable term-term-name), and also sets TERMINFO and TERMCAP.

The problem with termcap and terminfo is that they work optimally only if everyone has the same name→information database, which is not the case with remote logins. You can sometimes end up with a terminal name that's known locally, but not known on the remote host. And sometimes terminal emulators set TERM to a widely-supported name that only declares a subset of their capabilities, so as to work even on machines that don't have anything better in their database. In such cases, you might want to set TERM manually. For example, if you log in to a machine that doesn't know eterm-color, you might set TERM to eterm or vt100 instead (vt100 is a subset of most terminals' capabilities), either by setting term-term-name in Emacs if you open a Term buffer just to log in to that machine, or by setting TERM from your shell login script.


TERM is an environment variable, you set it in your environment. This could be the environment of a particular shell that you've opened, by running export TERM=foo, or all of your shells by adding the same command to your .bashrc (or a similar file for your shell, if you don't use bash. but you probably do use bash).

terminfo and termcap are databases containing information about terminals. A terminal was originally a hardware device that combined a display and a keyboard. Your computer would send commands to your terminal to tell it what to display, and of course the terminal would send most keyboard input to the computer (it would handle some keyboard input itself). These days your terminal is a software program running on the computer, but programs still talk to the terminal as if it were an external piece of hardware. The value you set this variable to depends on what program you're running. If you're running XTerm, then set it to "xterm". If you're running RXVT, then set it to "rxvt". And so on.

Anyway, the terminals were all designed and built by different companies who were all in competition with each other, and so they were all adding features as quickly as possible in order to out-do each other. Naturally, none of these companies designed their terminals using the same command set as their competitors; the sort of standardization we have with HTML and CSS today didn't exist back then. The termcap database was created to let you use any terminal you happened to want with your computer. A program could query the termcap database to find out what commands to use for your terminal. Ultimately the program wouldn't need to know anything about any particular terminal; it would just ask termcap how to do everything.

terminfo is a newer database than termcap. It contains essentially the same information, and can be considered interchangeable with termcap.

Programs that use termcap or terminfo look at the TERM environment variable to know what kind of terminal you're using; they pass the value along to the database when they make their queries.

The emacs shell and eshell modes are not really considered terminal emulators; they don't provide any capabilities for changing the text color or moving the cursor around.

term and ansi-term, on the other hand, provide essentially all the features you would expect from a mid-range terminal such as a VT100, or xterm. I don't actually know off-hand what TERM should be set to for these, but I think they set it for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.