After having upgraded a computer from Ubuntu 15.04 to 15.10 the colors in Emacs (which I run in the terminal with --no-window-system) have changed substantially and some text is now illegible. I would like to find out to change the colors back to how they were.

After. Output of M-x customize-create-theme in a 15.10 terminal (some faces change only the background leading to illegible text):

enter image description here

Before. Output of M-x customize-create-theme in a 15.04 terminal: (both foreground and background are changed)

enter image description here

Some investigation has led me to believe that the problem lies with having upgraded the terminal or some related application rather than Emacs: I installed version 24.5 from source on two computers, one running 15.04 and the other 15.10, and ran emacs -q -nw in various configurations:

  • On the 15.04 install, the colors are "right"
  • On the 15.10 install, the colors are "wrong"
  • SSH from 15.04 terminal to run the 15.10 install, the colors are "right"
  • SSH from 15.10 terminal to run the 15.04 install, the colors are "wrong"

So I'm guessing that the terminal is providing some information to Emacs about what colors it should use, but I can't work out any more than that.

Can someone help me to understand how the OS and terminal can affect Emacs' color scheme, and what I might be able to change to get the old colors back?

3 Answers 3


In general, a terminal application like emacs -nw has only very limited information about what colors are available. The shell will have an environment variable called TERM which contains the name of the terminal you're using. The application can then use a library such as terminfo to pick the right escape sequences to use each feature of the terminal. This design reflects the historical reality that there were hundreds of different types of terminals, and that they all had different capabilities, and that even when those capabilities overlapped they had different protocols for using them.

On a modern system you will likely only ever see four different values for this variable, as modern terminals have been replaced by terminal emulators. The most common value is xterm. This represents a terminal with the least-common-denominator of features, and most importantly supports 16 colors. Most terminals also support xterm-256color which extends this to 256 colors. (The other common values screen and screen-256color aren't as important here).

In the original 16 color setup, the terminal chooses the colors (and possibly allows the user to edit the selection). In the 256 color setup the terminal still chooses the colors, but the colors are chosen to be uniformly spaced so that all hues are more or less equally well represented.

So, how does this help you? Well, you can see that the color palette is entirely up to the terminal, so you'll want to find out how to configure it (or choose a different one). The emacs theme tells emacs a 24-bit color to use, then emacs looks at the TERM variable to see how many colors are available and makes a guess as to how to best map that 24-bit color into a palette entry, then the terminal takes that palette entry and maps it back into a 24-bit color to display on your monitor. (Unless your X-Windows display is in some other color mode, but that's super unlikely these days).

Another fix would be to run emacs not in a terminal but as a normal X application. This gives it access to the full 24-bit color space, the ability to use your entire selection fonts (with anti-aliasing even), multiple font sizes, text zooming, proportional fonts and more. Just run it without the -nw.


The basic faces (those not defined in some more specialized mode) are all defined in the lisp/faces.el source file. Here's the definition of the highlight face:

(defface highlight
  '((((class color) (min-colors 88) (background light))
     :background "darkseagreen2")
    (((class color) (min-colors 88) (background dark))
     :background "darkolivegreen")
    (((class color) (min-colors 16) (background light))
     :background "darkseagreen2")
    (((class color) (min-colors 16) (background dark))
     :background "darkolivegreen")
    (((class color) (min-colors 8))
     :background "green" :foreground "black")
    (t :inverse-video t))
  "Basic face for highlighting."
  :group 'basic-faces)

Obviously you can see that when there are more than 8 colors (16-color modes have 8 colors each with a bright and dark version) it doesn't set a background color. This doesn't answer the question "why", however. You should file a bug on emacs and suggest it; you'll either find the answer or get it changed :). Use M-x report-emacs-bug to send in the bug report. Naturally, including a patch that fixes it usually gets you mad props.

  • Extremely helpful, thanks. Have you any idea why Emacs sets a foreground color for the Highlight face in 16 color mode, but not 256 color mode? Do you know where these initial face definitions are in the source code? Commented Nov 7, 2015 at 19:41
  • An interesting observation; I've never noticed that before. One moment...
    – db48x
    Commented Nov 8, 2015 at 4:44

Make sure that your $TERM is set correctly before running Emacs.

If launching direct from the terminal, check with echo $TERM - preferably its value would be xterm-256color

Set it either directly before you run Emacs:

TERM=xterm-256color emacs -nw 

With any other arguments you need.

As a more permanent solution, set the value of TERM in your terminal emulator setup.

  • 1
    setting TERM in your shell startup scripts is a bad idea. Tell your terminal emulator what TERM it should set instead.
    – casey
    Commented Nov 8, 2015 at 13:13
  • Agreed, the terminal should dictate TERM's value.
    – ocodo
    Commented Nov 8, 2015 at 13:39

I hit exactly the same problem when upgrading to Ubuntu 16.04 (from U14.04 LTS). The new value of the TERM variable (as mentioned in several other answers) seemed to be a culprit. The solution was to set the TERM variable to value 'xterm' instead of the current default 'xterm-256color':

TERM=xterm emacs -nw

brought back the old colors, legible on dark backgrounds. NB. The new 256 color palette seems to be optimized for a dark text on a light background...

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.