139

After the installation of OSX Lion, I tried to:

nano /etc/apt/sources.list

But I get this error:

Error opening terminal: xterm-256color

If I try to switch terminal.app preferences to open terminal windows in "xterm color" instead of xterm-256color everything works fine.

What's happening?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Luke
  • 2,976
  • 6
  • 34
  • 44
  • 1
    You might be missing some step here - like you ssh'ed from the Mac into some Debian or Ubuntu system, right? At least I hope you didn't try to edit /etc/apt/sources.list in a MacOS System... :) – Henning Aug 10 '17 at 14:54

11 Answers11

217

On Red Hat this worked for me:

export TERM=xterm

further info here: http://www.cloudfarm.it/fix-error-opening-terminal-xterm-256color-unknown-terminal-type/

Meetai.com
  • 6,622
  • 3
  • 31
  • 38
  • Worked for me when ran on the remove system. Connection from was OS X -> Ubuntu – Ryan Griffith Jul 04 '16 at 14:09
  • Interestingly, I had this error in a chroot-ed environment that has only minimal programs so far. I assume that there is some program missing that causes this, but unfortunately nano does not give more information as to why it exactly fails. – shevy Aug 29 '16 at 21:36
  • Works also when trying to use top inside a minikube local kubernetes system running as a VM based on buildroot inside Virtualbox on Max OS X. (which is ssh from MacOS into a Buildroot based VM and tgen run top) – Henning Aug 10 '17 at 14:50
  • The same solution seems correct for different systems, including Ubuntu/Debian and OSX (the OP's). How is this irrelevant? – Meetai.com Sep 22 '17 at 19:18
  • This worked for me on a Debian system. How do I make this permanent? Such as having it occur when I log in via SSH? – inspirednz Jul 23 '18 at 23:42
  • While this may work (and even more generically than the "real" solutions) it's conceptually a workaround at best. You're essentially lying to your shell about the terminal you use to connect. – das-g Aug 26 '18 at 21:07
  • It might be a "hack" that sheds light in the underlying issue. – Meetai.com Oct 06 '18 at 16:12
  • This worked for me when ccmake, instead of nano, was issuing the same error message – XavierStuvw Oct 24 '19 at 12:58
  • This hack also works on QNAP NAS after installing iotop qpkg to the BSD OS – tobi delbruck Jan 29 '23 at 09:46
30

After upgrading to OSX Lion, I started getting this error on certain (Debian/Ubuntu) servers. The fix is simply to install the “ncurses-term” package which provides the file /usr/share/terminfo/x/xterm-256color.

This worked for me on a Ubuntu server, via Erik Osterman.

calvinf
  • 3,754
  • 3
  • 28
  • 41
22

I can confirm this is a terminfo issue. This is what worked for me. SSH in to the remote machine and run

 sudo apt-get install ncurses-term

Boom. Problem solved.

John
  • 3,866
  • 6
  • 33
  • 37
  • I think this may be one reason why nano may sometimes fail - e. g. if the problem happens at ncurses/terminfo instead. – shevy Aug 29 '16 at 21:38
8
  1. edit your .bash_profile file

    vim .bash_profile

  2. commnet

    #export TERM=xterm-256color

  3. add this

    export TERMINFO=/usr/share/terminfo

    export TERM=xterm-basic

    to your .bash_profile

  4. finally

    run:

    source .bash_profile

Xu Radman
  • 81
  • 1
  • 3
6

I had this problem connecting to http://sdf.org through Mac OS X Lion. I changed under Terminal Preferences (+,) > Advanced pane, Declare Terminal as to VT-100.

I also marked Delete Sends Ctrl-H because this Mac connection was confusing zsh.

It appears to be working for my use case.

isomorphismes
  • 8,233
  • 9
  • 59
  • 70
6

I, too, have this problem on an older Mac that I upgraded to Lion.

Before reading the terminfo tip, I was able to get vi and less working by doing "export TERM=xterm".

After reading the tip, I grabbed /usr/share/terminfo from a newer Mac that has fresh install of Lion and does not exhibit this problem.

Now, even though echo $TERM still yields xterm-256color, vi and less now work fine.

tshepang
  • 12,111
  • 21
  • 91
  • 136
bitaxis
  • 69
  • 1
  • For anyone trying to get a chroot running on macOS, this fixes "Error opening terminal: " issue inside the chroot. –  Sep 04 '18 at 19:31
3

somehow and sometimes "terminfo" folder comes corrupted after a fresh installation. i don't know why, but the problem can be solved in this way:

1. Download Lion Installer from the App Store
2. Download unpkg: http://www.macupdate.com/app/mac/16357/unpkg
3. Open Lion Installer app in Finder (Right click -> Show Package
Contents)
4. Open InstallESD.dmg (under SharedSupport)
5. Unpack BSD.pkg with unpkg (Located under Packages)   Term info
will be located in the new BSD folder in /usr/share/terminfo

hope it helps.

Luke
  • 2,976
  • 6
  • 34
  • 44
  • I encountered the same error and tried your suggested steps. I encountered a number of permission denied errors while unpacking with unpkg. The BSD folder appeared on my desktop, and I ran "sudo mv ~/Desktop/BSD/usr/share/terminfo /usr/share/terminfo" then restarted terminal, but I still get the same "Error opening terminal: xterm-256color" error. – Mike Lawrence Jul 24 '11 at 05:23
  • 1
    maybe you can try this http://www.sendspace.com/file/hc2dus it's my terminfo folder. after replacing it, don't forget to chmod 555 /usr/share/terminfo – Luke Jul 24 '11 at 14:55
1

Mine was quite a unique case but this could help someone. On Android I tried to copy nano from my termux binary folder to /system/xbin. Placed all the library dependencies in /system/lib and got this error. The libncurses.so.6 file I copied from termux had it's TERMINFO file still pointed to /data/data/com.termux/files/usr/share/terminfo

View pointed path with command

strings path-to-libncurses.so | grep /terminfo

To fix either make the termux terminfo dir and subdirs readable and executable by the nano user or copy the terminfo folder somewhere else and use a hexeditor to modify the plain text path in the shared library file.

Link to zipped terminfo folder https://drive.google.com/file/d/1m1tfHgkGRehBGh1jPMK4EaTgQb9EyCG7/view?usp=drivesdk

Fortune
  • 162
  • 1
  • 4
  • I ran to a similar situation when uding a chroot ssh configuration. And I fixed it as @Fortune has menstioned. find and copy terminfo folders to the chroot folder structure – Gayan Kavirathne May 30 '20 at 19:12
0

You can add the following in your .bashrc

if [ "$TERM" = xterm ]; then TERM=xterm-256color; fi
doesnt_matter
  • 121
  • 5
  • 13
0

I hear that this can be fixed by overwriting your /usr/share/terminfo with one from the computer of somebody with a working install of Lion. I can't confirm whether this works or not, and unfortunately I haven't upgraded yet, so I can't provide you with that file.

EdoDodo
  • 8,220
  • 3
  • 24
  • 30
0

This worked for me on linux mint, based on the link provided by @Meetai.com.
Put this in .bashrc and restart the terminal:

TERM="xterm"
export TERM

Srdjan Milic
  • 328
  • 2
  • 14