The TERM environment variable not set
message is a frustrating error that can render your Linux system widely unusable, at least from the command line. In this tutorial, you will see how to resolve the error.
In this tutorial you will learn:
- How to fix the
TERM environment variable not set
error message on Linux

Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | N/A |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
TERM environment variable not set – Solution
Having the TERM environment variable improperly set or unset completely can cause various errors depending on the program you are trying to use in terminal. A few that you may have seen are:
$ less newfile.txt WARNING: terminal is not fully functional $ clear '': unknown terminal type. $ mysql -p Enter password: TERM environment variable not set.
The cause of this issue is that the TERM environment variable is not properly configured. But it is simple enough to fix. In the examples below, we will set our TERM variable to xterm-256color
, which is normally the proper setting across all major Linux distros. However, use a different value if required on your system.
- To fix the error in your current session only:
$ export TERM=xterm-256color
- To permanently fix the error for all sessions owned by your current user:
$ echo 'export TERM=xterm-256color' >> ~/.bashrc $ source ~/.bashrc
- To permanently fix the error system wide for all users, update the variable inside of the
/etc/environment
file.$ sudo echo 'TERM=xterm-256color' >> /etc/environment
For more information about setting environment variables, see our tutorial on How to set and list environment variables on Linux.
Closing Thoughts
In this tutorial, we saw how to set the TERM environment variable on a Linux system. With a misconfigured TERM variable, you will find that many programs do not work on the command line, and you will continuously encounter errors that tell you your terminal variable is incorrect.