How to Check Terminal UTF-8 Support for CPAN Module Installation on CentOS 5


1 views

When installing Perl modules via CPAN on legacy systems like CentOS 5, you'll often encounter the prompt: "Does your terminal support UTF-8?". Here are reliable methods to verify this:

The most straightforward way is to run:

echo -e '\xe2\x98\xa0'

If your terminal displays a skull-and-crossbones symbol (☠), UTF-8 is supported. For a more programmatic approach in Perl:

perl -e 'print "\x{263A}\n"'

Examine your locale settings:

locale | grep -E 'LANG|LC_CTYPE'

UTF-8 supporting terminals typically show values ending with '.UTF-8', like en_US.UTF-8.

Different terminals handle UTF-8 differently:

  • Gnome Terminal: Full UTF-8 support since version 2.16+
  • Konsole: UTF-8 enabled by default
  • xterm: Requires -u8 flag or UXTerm variant

If uncertain, you can explicitly configure CPAN:

export PERL_MM_USE_DEFAULT=1
export PERL_UTF8_LOCALE=1
cpan

Create a test script check_utf8.pl:

#!/usr/bin/perl
use strict;
use warnings;
use Encode qw(is_utf8);

my $test_char = "☯";
print "Terminal UTF-8 support: ";
print is_utf8($test_char) ? "YES" : "NO";
print "\n";

For CentOS 5 specifically, you might need to manually set locales:

localedef -c -f UTF-8 -i en_US en_US.UTF-8
export LC_ALL=en_US.UTF-8

If UTF-8 isn't available, configure CPAN with:

o conf prerequisites_policy follow
o conf commit

This makes CPAN automatically handle encoding requirements.


When configuring CPAN modules on legacy systems like CentOS 5, terminal encoding compatibility becomes crucial - especially when handling international character sets. The UTF-8 check is particularly important for:

  • Proper display of module installation prompts
  • Accurate logging of build processes
  • Handling module metadata containing non-ASCII characters

Here are three reliable ways to test UTF-8 support:

# Method 1: Echo test
echo -e '\xe2\x82\xac'  # Should display € symbol if UTF-8 supported

# Method 2: Locale check
locale | grep -E 'LANG|LC_'  # Look for UTF-8 in output

# Method 3: Perl test script
perl -e 'use Encode; print "Terminal ", (Encode::is_utf8($ENV{LANG}) ? "supports" : "does NOT support"), " UTF-8\n";'

If tests fail, implement these fixes before CPAN setup:

# Permanent solution (add to ~/.bashrc or /etc/profile)
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

# Alternative for minimal systems
stty iutf8  # Enable UTF-8 input processing

When running CPAN configuration:

# Force UTF-8 mode regardless of terminal detection
PERL_UTF8_LOCALE=1 cpan

# Verify settings after configuration
perl -MCPAN -e 'CPAN::HandleConfig->prettyprint("term_is_latin")'

For older terminals like xterm or linux console:

  • Install compatible fonts: yum install terminus-fonts
  • Set terminal type explicitly: export TERM=xterm-256color
  • Consider using screen/tmux with UTF-8 support