How To Enable Syntax Highlighting in Nano on Linux and Ubuntu
Nano is pretty straightforward, and most people use it in a pinch for quick edits. But without syntax highlighting, reading through code or config files can get kinda tedious, especially when you’re dealing with multiple languages or configs. If Nano’s default looks plain and boring, definitely worth enabling syntax highlighting so you can see what’s what at a glance. That way, debugging and editing actually becomes a lot easier. Just a couple of tweaks and you’ll have colorful code in Nano—nothing too fancy, but enough to save you some headaches.
How to Enable Syntax Highlighting in Nano
Access the Nano configuration file
This is where the magic happens. You want to open /etc/nanorc with sudo because it’s a system file, and that’s usually protected. Use this command in your terminal:
sudo nano /etc/nanorc
If the file doesn’t exist, Nano will create it, but normally it’s there already. Note: on some setups, people prefer copying a repository of syntax files into their home directory, like from scopatz/nanorc, which is a pretty popular collection of nano syntax files.
Find the include lines and uncomment them
Scroll through the file (using arrow keys). You’ll spot a bunch of lines starting with # include "/usr/share/nano/somefile.nanorc"
. These lines define which syntax files Nano can use. Because they’re commented out (with the #), Nano ignores them. So, remove the #
at the start of lines for the languages you want to activate. For example, to get Python and HTML syntax highlighting, you’d change:
# include "/usr/share/nano/python.nanorc"
# include "/usr/share/nano/html.nanorc"
to
include "/usr/share/nano/python.nanorc"
include "/usr/share/nano/html.nanorc"
And do this for all other languages you care about. It’s kind of weird, but on some installs, these lines are there but just commented out, so this step makes all the difference.
Save your changes
Press Ctrl + O to save, then hit Enter to confirm. Exit Nano by pressing Ctrl + X. That’s it for configuration.
Test it out
Open a file with Nano that matches one of your enabled syntax rules. If everything went right, you should see color-coded syntax highlighting. It’s not like a full IDE, but it’s pretty convincing and makes scanning code way easier. If it’s not working, double-check the include paths or whether you need to install some syntax files separately. On some setups, people also prefer doing this in the local home directory like ~/.nanorc
instead of the system-wide one, especially if multiple users are involved.
Extra tips & common pitfalls
If highlighting feels sluggish or some syntax rules aren’t showing up, make sure Nano is up to date:
sudo apt update && sudo apt upgrade nano
And verify that the paths to the nanorc files are correct. Because, of course, Linux has to make it complicated sometimes. Also, if you want more languages or themes, you can clone a larger nanorc collection, like this:
scopatz/nanorc on GitHub. Just clone or download it, then include those files in your main nanorc
.
Summary
- Open /etc/nanorc with
sudo nano
- Uncomment include lines for desired languages
- Save, exit, and test by opening a code or config file
- Consider updating Nano or grabbing a larger nanorc collection for more syntax support
Wrap-up
Getting syntax highlighting set up in Nano isn’t rocket science, but it’s a huge productivity boost once it’s done. It’s pretty surprising how much clearer code looks with just a dash of color. Now, every time that syntax highlighting works, it’s like a little win—makes clearing out those long coding sessions a tad less dreary. On a few machines, the include lines needed some fiddling, and on others, the syntax files weren’t installed by default, so keep that in mind. Fingers crossed this helps someone avoid squinting at plain text all day.