Enable Syntax Highlighting in GNU nano on Servers and Containers
Add one include line to ~/.nanorc to get color syntax highlighting in nano, and verify it works on your terminal.
06 Aug 2026, 14:26 UTC

The problem: nano opens every file in plain white text
You connect to a remote server or container, open a shell script or Nginx config in nano, and everything renders in a single color. Comments, keywords, and variables look identical, so a misplaced character or an unclosed quote is harder to spot. The fix is usually one configuration line, but it only works if your terminal and nano build support color.
How nano loads syntax rules
GNU nano applies highlighting through nanorc files. System syntax definitions are typically installed under /usr/share/nano/ with names like sh.nanorc, c.nanorc, or python.nanorc. Nano does not read them automatically unless your user configuration tells it to.
The user configuration file is ~/.nanorc in your home directory. A single include directive pulls in every system syntax file:
include "/usr/share/nano/*.nanorc"
Paths and package names differ by distribution. Debian and Ubuntu usually ship these files in the nano or nano-tiny package; RHEL-based systems may place them under /usr/share/nano/ as well, while Alpine Linux keeps them in the nano-doc or nano subpackage depending on the release. Check your local man nanorc page for exact paths.
Worked example: enable and verify highlighting
- Check the installed nano release. Run this in your shell; no special permissions are needed:
nano --version
Look for the version number and confirm the build was not compiled without color support.
- Add the include directive to your user config. Run this in your user shell:
printf 'include "/usr/share/nano/*.nanorc"\n' >> ~/.nanorc
This appends the line to ~/.nanorc. If you run it more than once, the directive will appear multiple times, which is harmless but untidy.
- Open a file that matches a system syntax rule in a color-capable terminal:
nano ~/.bashrc
or
nano example.sh
Expected check: keywords such as if, then, or fi should appear in color. If the file is monochrome, highlighting is not active.
- Confirm that color is suppressed without terminal support:
TERM=dumb nano example.sh
On a dumb terminal, nano disables color and redraws the file in monochrome. This is expected behavior, not a bug.
Permissions and risk
Editing ~/.nanorc requires write access to your home directory, which you normally have. No sudo is required. The only state change is the appended line in your user config; removing that line restores the previous behavior.
Limitations and what to watch for
- Terminal color support. Highlighting requires a color-capable terminal. It is suppressed on
dumbterminals or when nano was compiled without color support. - Regular expression flavor. Nano uses POSIX extended regular expressions for syntax patterns. Patterns from other editors that use advanced regex features may not work.
- Large single-line files. The cost is negligible for typical configuration files, but very long single lines can increase redraw latency even with soft wrapping disabled.
- Distribution differences. Syntax file locations vary, so the glob
/usr/share/nano/*.nanorcmay match nothing on a minimal container image.
Practical way to check the result
Open a file with a known extension in nano while connected through a normal terminal emulator. If comments and keywords are colored, the include directive worked. If not, run nano --version, check that /usr/share/nano/*.nanorc exists, and confirm your terminal reports a color-capable TERM value such as xterm-256color.
Rollback
Because this change only appends one line to ~/.nanorc, rollback is manual: open ~/.nanorc in nano, delete the include line, save, and exit. Nano will return to syntax-free highlighting.
Actionable closing
Add the include line to ~/.nanorc, open a script in your usual terminal, and confirm the colors appear. If they do not, the culprit is usually a missing syntax package, a dumb terminal, or a nano build without color support. You can verify each with the checks above.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.