I've got nano 2.0.6 as default in my Mac OS X terminal when executing nano. I've got nano 2.9.1 in /usr/local/Cellar/nano/2.9.1/bin/nano.

How do I change the default nanoto version 2.9.1 in the terminal?

I'm running Mac OS X 10.13.1.


This another answer is good, especially as a temporary override. For the sake of completeness this is the main point of it:

export PATH="/usr/local/Cellar/nano/2.9.1/bin:$PATH"

The problem is: if you need a permanent solution for multiple tools then with such a simple approach your $PATH will unnecessarily bloat.

This is how to avoid this (on Debian; the question is for Mac OS X but I believe the solution also applies or can be easily adapted). First create your own bin/:

mkdir ~/bin/

(Edit: on macOS, ~/Library/bin/ fits the home folder organization a bit better. I decided not to change my answer though, adapt this path to your needs.)

Next modify your $PATH:


(See note 1 down below if you want to make it permanent.)

Then symlink the desired nano (and any other binary) to your custom bin/:

ln -s /usr/local/Cellar/nano/2.9.1/bin/nano ~/bin/

(See note 2 down below if you want to use this nano right away.)

This approach has the following advantages:

  • your $PATH stays relatively short and clean;
  • with ls -l ~/bin/ you can easily tell which tools you do override with what; this is much better than analyzing a bloated $PATH which specifies directories; every directory may include many executables and you need to ls anyway to know them;
  • removing a symlink, creating it anew is way easier than modifying $PATH, especially from within a script;
  • you can also place your own scripts in ~/bin/.

Note 1: in my Debian the /etc/skel/.profile includes the following code:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then

My ~/.profile was created as a copy of /etc/skel/.profile, so the code is there from the very beginning. This means every new shell session adjusts its $PATH to include my private bin/; all I had to do was create the directory.

Note 2: while modifying $PATH in the middle of a session (e.g. to test my solution) keep in mind your shell may remember the old location of any executable it had already looked up according to the old $PATH. Common shells use hash builtin to manage this. Use hash -r if needed.

If you customize $PATH at the very beginning of a shell session (like in .profile) then there's no such problem.

  • On macOS, ~/Library/bin fits the home folder organization a bit better. ~/Library is a hidden folder containing things that're accessed automatically (e.g. by inclusion in $PATH) rather than by manually selecting them (e.g. in an "Open" dialog). – Gordon Davisson Dec 7 '17 at 7:29
  • @GordonDavisson Thank you. My answer now mentions this. – Kamil Maciorowski Dec 7 '17 at 7:51

You can create a symbolic link from /usr/local/Cellar/nano/2.9.1/bin/nanoto /usr/local/bin

ln -s /usr/local/Cellar/nano/2.9.1/bin/nano /usr/local/bin/nano

or you could create an alias.

alias nano=/usr/local/Cellar/nano/2.9.1/bin/nano


export PATH="/usr/local/Cellar/nano/2.9.1/bin:$PATH"

does the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.