Skip to content

Instantly share code, notes, and snippets.

@BlakeGardner
Last active August 18, 2025 18:20
Show Gist options
  • Save BlakeGardner/5587269 to your computer and use it in GitHub Desktop.
Save BlakeGardner/5587269 to your computer and use it in GitHub Desktop.
Syntax highlighting in nano on Mac OS
# Last updated May, 2024 for Apple silicon Macs
# Install Homebrew if you don't already have it: https://brew.sh
# install nano from homebrew
brew install nano nanorc
# update your nanorc file
echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc
# close and re-open your terminal and you'll have syntax highlighting
@lorthirk
Copy link

+1 on @hacker1024 comment. single include with *.nanorc works for me as well.

@regexyl
Copy link

regexyl commented Jun 20, 2021

Thanks this worked! Is there any reason why the syntax highlighting only applies to nano, not sudo nano though?

@lorthirk
Copy link

Thanks this worked! Is there any reason why the syntax highlighting only applies to nano, not sudo nano though?

In order to have it for sudo nano you have to edit the .nanorc for the root user

@regexyl
Copy link

regexyl commented Jun 20, 2021

@lorthirk That makes sense. Thanks for the help!

@romantech
Copy link

romantech commented Aug 22, 2021

Why does every file need to be listed? The following works for me:

brew install nano
echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

This is nice! It works fine for me. Thank you!

@secfb
Copy link

secfb commented Oct 4, 2021

Mac OSX Big Sur
nano version:5.8

brew install nano 
echo 'include "/opt/homebrew/Cellar/nano/5.8/share/nano/*.nanorc"'>> ~/.nanorc

@robert-duplock-adg
Copy link

robert-duplock-adg commented Dec 13, 2021

Thanks @secfb (above), it worked beautifully on an M1 Mac running Monterery & zsh.
I ran:

brew install nano 
# Restart terminal
nano -V 
# Note the version number
echo 'include "/opt/homebrew/Cellar/nano/NANO_VERSION_NUMBER/share/nano/*.nanorc"'>> ~/.nanorc
# EG: echo 'include "/opt/homebrew/Cellar/nano/5.9/share/nano/*.nanorc"'>> ~/.nanorc

@tagplus5
Copy link

Brew creates symlink so you don't need set nano version number:
echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

@bbuchheim
Copy link

or for Apple Silicon: echo 'include "/opt/homebrew/Cellar/nano/*/share/nano/*.nanorc"' >> ~/.nanorc

@BlakeGardner
Copy link
Author

Brew creates symlink so you don't need set nano version number: echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

Thanks @tagplus5, updated the gist for Apple Silicon

@phillco
Copy link

phillco commented Apr 7, 2022

or for Apple Silicon: echo 'include "/opt/homebrew/Cellar/nano//share/nano/.nanorc"' >> ~/.nanorc

Thanks! It's weird that you have to encode the wildcard for the version and you don't get a nice symlink like /usr/local/share/nano/ on Intel Macs. Hopefully there's only one version there at a time!

@eureka-cpu
Copy link

Brew creates symlink so you don't need set nano version number: echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

Thanks @tagplus5, updated the gist for Apple Silicon

This worked for me, brew install nano and then this command. Thanks! (on M1 MBP)

@IoannisTM
Copy link

for me what worked is

echo "include /opt/homebrew/Cellar/nano/6.3/share/nano/*.nanorc" >> ~/.nanorc

@up9cloud
Copy link

brew install nano
echo include "$(brew --prefix nano)/share/nano/*.nanorc" >> ~/.nanorc

or

brew install nano
brew install nanorc
echo include "$(brew --prefix nanorc)/share/nanorc/*.nanorc" >> ~/.nanorc

@x86txt
Copy link

x86txt commented Nov 8, 2022

latest is:

echo "include /opt/homebrew/Cellar/nano/6.4/share/nano/*.nanorc" >> ~/.nanorc

@x86txt
Copy link

x86txt commented Nov 27, 2022

For macOS Ventura:

brew install nano nanorc

echo "include /opt/homebrew/Cellar/nano/7.0/share/nano/*.nanorc" >> ~/.nanorc

Note you might want to take this opportunity to just start with a clean .nanorc if you've been upgrading nano and nanorc frequently.

mv ~/.nanorc ~/.nanorc.orig && echo "include /opt/homebrew/Cellar/nano/7.0/share/nano/*.nanorc" > ~/.nanorc

@RobThree
Copy link

RobThree commented Feb 15, 2023

@x86txt: Replace the …/nano/7.0/share/… part with …/nano/*/share/… so you don't have to keep updating your .nanorc file every time nano updates to a newer version.

@dhorster
Copy link

Worked for me:

brew install nano nanorc
echo 'include "/usr/local/Cellar/nano/*/share/nano/*.nanorc"' >> ~/.nanorc

@s-ota-66
Copy link

Worked for me:

brew install nano nanorc
echo 'include "/opt/homebrew/share/nanorc/*.nanorc"' >> ~/.nanorc

macOS Ventura 13.2.1
Homebrew 4.0.13

@BlakeGardner
Copy link
Author

Thanks, updated the gist @s-ota-66

@benolot
Copy link

benolot commented Apr 22, 2023

Thanks all for the guide! Can confirm current version is working on 13.3.1

@ryenus
Copy link

ryenus commented May 11, 2023

Better to use $(brew --prefix) to work with both Intel & ARM chips

brew install nano nanorc
echo "include \"$(brew --prefix)/share/nanorc/*.nanorc\"" >> ~/.nanorc

@nospam2k
Copy link

nospam2k commented Nov 24, 2023

echo 'include "/usr/local/Cellar/nano/*/share/nano/*.nanorc"' >> ~/.nanorc

Works for Sonora

@firstrecall
Copy link

firstrecall commented Nov 29, 2023

echo 'include "/usr/local/Cellar/nano/*/share/nano/*.nanorc"' >> ~/.nanorc

Probably it would be better to use

echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc

so in such case it will use the right path depends on if mac uses Intel or Apple Silicon

@tobsn
Copy link

tobsn commented May 13, 2024

as of today, may 13th 2024, the following works without issues on sonoma 14.4.1 with and brew 4.2.21:

brew install nano
echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc

thanks everyone for keeping this going :)

@BlakeGardner
Copy link
Author

Updated the gist thanks @tobsn

@hsiktas
Copy link

hsiktas commented Apr 19, 2025

It took me way too long to notice that the /usr/bin/nano that comes with macOS is actually "UW PICO 5.09". GNU nano installed via homebrew immediately followed that .nanorc and applied syntax highlighting. 😄

@w601sxs
Copy link

w601sxs commented Jul 23, 2025

as of today, may 13th 2024, the following works without issues on sonoma 14.4.1 with and brew 4.2.21:

brew install nano
echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc

thanks everyone for keeping this going :)

+1 thanks @tobsn

@BryanPoulin
Copy link

BryanPoulin commented Aug 18, 2025

As of today, may 13th 2024, the following works without issues on macOS Sequoia 15.6 (24G84) and Homebrew 4.6.4:

brew install nano
echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc

@BryanPoulin
Copy link

BryanPoulin commented Aug 18, 2025

Why does every file need to be listed? The following works for me:

brew install nano
echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

The main difference between the two code snippets lies in how they handle the installation and configuration of nano and nanorc using Homebrew on macOS.

Key Differences:

  • Installation of nanorc: The first snippet (@BlakeGardner) explicitly installs nanorc, while the second snippet (@lorthirk) does not. However, nano might still include syntax highlighting files that can be used without the separate nanorc formula.
  • Path Dynamism: The first snippet dynamically finds the path to nano Cellar and includes syntax highlighting files from there. The second snippet uses a fixed path that assumes Homebrew's standard symlink behavior.
  • Flexibility and Portability: The dynamic path approach in the first snippet might be more flexible and resilient to changes in Homebrew's directory structure or nano formula. The fixed path in the second snippet might break if Homebrew changes its symlink structure or if nano formula's installation path changes.

Choosing Between Them

  • Use the first snippet if you want to ensure you're getting the syntax highlighting configurations specifically packaged with nano in a way that's dynamically linked to Homebrew's Cellar structure.
  • Use the second snippet if you're relying on the standard Homebrew symlink structure and want a simpler configuration line, assuming nano includes necessary syntax highlighting files in /usr/local/share/nano/.

Given the current Homebrew structure and nano formula, both approaches should work, but the dynamic path might offer more future-proofing against changes in Homebrew or the formulae.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment