I try to run a game in my terminal on Ubuntu 16.04, a game which was made using c ncurses library. At the time the game was finished, it had ran as I was expected in terminal. Then I've made some changes to a file (maybe .bashrc), such that I could use 256 color palette for my game.

Now, when I try to run the game I'm getting this error message:

Error opening terminal: xterm-256color.

TERM variable is set to xterm-256color and tput colors output is 256. Is there a more appropriate method for testing if my terminal uses 256 colors with certainty and how can I solve the problem described above?


There's no 100% reliable method for determining if a terminal supports a given number of colors. You set TERM to tell applications to use a particular terminal description, so that ncurses and other libraries know how to work with the terminal.

The xterm-256color description is part of ncurses-base, an essential package:

$ dlocate /lib/terminfo/x/xterm-256color
ncurses-base: /lib/terminfo/x/xterm-256color

If your application cannot open it, that's likely because you have an environment variable set (such as TERMINFO) which tells ncurses to look in a place where that description does not exist.

You can use strace to see which files are opened by an application, and (usually) see problems of this sort, e.g., by looking for failed opens of "xterm-256color".

Further reading:

  • TERMINFO, environment variable in the ncurses manual page
| improve this answer | |
  • If I run in terminal the command "echo $TERMINFO" it outputs a blank row, so TERMINFO is not set. I don't understand this row from TERMINFO documentation, which says that the following directory might change the location where ncurses searches for my terminal info: "the last directory to which ncurses wrote, if any, is searched first." Something else, the TERMINFO_DIRS variable is not set, because it echos a blank row, too. Maybe I have to specify this too, I've programmed this game I'm trying to run on Ubuntu 14.04. – Iulian Barbu Aug 16 '16 at 14:13
  • The output of the command that you've specified in your post is the same as yours. – Iulian Barbu Aug 16 '16 at 14:16
  • I don't know how I didn't saw that you said to me to use STRACE command, because that is what I needed for seeing where ncurses searches for XTERM-256COLOR. I had to copy my xterm-256color compiled terminfo file from /lib/terminfo/x/ directory to /usr/share/terminfo/x directory. From then I can run my game, but after closing the game my prompt colors are changed. Surely I need to modify something into an env variable. At least I can run the game. Thank you for help! – Iulian Barbu Aug 17 '16 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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