How to enable 256 color terminal in Ubuntu ?

2

Enable 256 Color Terminal in Ubuntu


Some times when you try to set the colorscheme of your terminal based editors such as vim or tumx, colors looked pretty strange. It was not as promised in theme screenshot!

when you try to set the colorscheme of your terminal based editors, colors looked pretty strange. because our terminal supported 8 bit colors only while we were trying to set 256 colors in the terminal.

It was happening because our terminal supported 8 bit colors only while we were trying to set 256 colors in the terminal.
So first we have to get some information about our terminal – We would run following commands to check the details about the color depth of terminal, type of terminal etc.
Type these commands and check your results:

tput colors

This will report how many colors your terminal is using.

echo $TERM

This will tell you what terminal you are using.

echo $COLORTERM

If you are using a gnome you should see “gnome-terminal”

If you get the result of tput colors as 256 then voila! your system already has 256 color terminal otherwise if you get something less than 256 then you need some work to Enable 256 Color Terminal.

Enable 256 Color Terminal in Ubuntu - techcresendo
Enable 256 Color Terminal in Ubuntu

The gnome-terminal in latest versions of Ubuntu already supports 256 colors, however it still reports its term type as “xterm” indicating it supports only 8 colors. Since $TERM is set to “xterm” which is just 8 bit terminal and applications such as “tmux”,“vim” decides the number of supported colors based on environment variable “TERM”.
Lot of people suggest using below code in you .bashrc file in order to Enable 256 Color Terminal but in my opinion this should be avoided because environment variable “TERM” should be reported by the terminal instead of the shell. It can raise confilict when other applications such as putty try to use it.

if [ "$COLORTERM" == "gnome-terminal" ] || [ "$COLORTERM" == "xfce4-terminal" ]
then
TERM=xterm-256color
elif [ "$COLORTERM" == "rxvt-xpm" ]
then
TERM=rxvt-256color
fi

You can follow another but simple approach to Enable 256 Color Terminal in Ubuntu as shown in screenshot –

Enable 256 Color Terminal in Ubuntu - techcresendo
Enable 256 Color Terminal in Ubuntu

Replace with version of your shell e.g Zsh or Bash

Enable 256 Color Terminal in Ubuntu - techcresendo
Enable 256 Color Terminal in Ubuntu

Now after making the changes lets run those command again to see the changes

Enable 256 Color Terminal in Ubuntu - techcresendo

Awesome! Now we enabled 256 colors in Ubuntu terminal as we can see in the screenshot.

Another Approach ( Only if you are using Oh My Zsh)-

256color ZSH Plugin is a plugin for Oh My Zsh. If you use Oh-My-Zsh, add zsh-256color to your plugins list and clone this repository to your $ZSH_CUSTOM/plugins directory:

 $ ( cd $ZSH_CUSTOM/plugins && git clone https://github.com/chrissicool/zsh-256color )

As per their description is given on github –

256color ZSH plugin enhances the terminal environment with 256 colors. It looks at the chosen TERM environment variable and sees if there is respective(n-)curses’ termcap/terminfo descriptors for 256 colors available. The result is a multi color terminal, if available

If you do not want to use this plugin and manually install using ncurses.

sudo apt-get install ncurses-term

So these are the ways to Enable 256 Color Terminal in Ubuntu and another approaches or suggestions to do the same are welcome.

2 COMMENTS

    • Cygwin terminal is actually emulation of actual terminal of linux for windows which may be having fullest capability of actual terminal but still you can try following – Right-click in mintty, then in Options…->Terminal, change type to xterm-256color, click OK, close mintty and re-launch it.

Leave a Reply to Sudhir Mishra Cancel reply

Please enter your comment!
Please enter your name here