Skip to content

Instantly share code, notes, and snippets.

@fevangelou
Last active January 3, 2024 14:43
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save fevangelou/be744753730e86b8783fd481f311a7c9 to your computer and use it in GitHub Desktop.
Save fevangelou/be744753730e86b8783fd481f311a7c9 to your computer and use it in GitHub Desktop.
Install Nano Editor (with syntax highlighting) on MacOS without using Homebrew [updated Jan 2024]
#!/bin/bash
# Install Nano Editor (with syntax highlighting) on MacOS without using Homebrew
# You can get the latest version number from https://www.nano-editor.org
# Instructions:
# - First off, download this Bash script from the browser & make it executable:
# $ chmod +x install_nano_on_macos_without_homebrew.sh
# - If you have "wget" installed (you most likely do), just run the script with:
# $ ./install_nano_on_macos_without_homebrew.sh
# ...and you're ready.
# - If you don't have "wget" installed, download the latest release of the Nano Editor in *.tar.gz
# from https://www.nano-editor.org and make sure the version referenced in the *.tar.gz file is also
# referenced in the VERSION specified after these comments & then run the script with:
# $ ./install_nano_on_macos_without_homebrew.sh
# ...which will use the file your downloaded for the Nano Editor to install it directly.
VERSION="7.2" # As of Jan 2024 - set the version number here
cd ~/Downloads
if [ ! -f "nano-${VERSION}.tar.gz" ]; then
wget -O nano.tar.gz https://www.nano-editor.org/dist/latest/nano-${VERSION}.tar.gz
fi
tar -xvf nano.tar.gz
mv nano ~/.nano
cd ~/.nano
./configure
make
sudo make install
touch ~/.nanorc
cat > "~/.nanorc" <<EOF
## Some defaults
set autoindent
set historylog
set indicator
set linenumbers
set locking
set mouse
set softwrap
set stateflags
set tabsize 4
set tabstospaces
## Enable syntax highlighting in Nano
include ~/.nano/syntax/*.nanorc
EOF
exit
@fevangelou
Copy link
Author

fevangelou commented Mar 24, 2019

Hint: "wget" can be easily installed with "brew install wget" if you have Homebrew installed on your Mac.

Screenshot (editing .js file): https://jmp.sh/0VG9K9A

@fevangelou
Copy link
Author

fevangelou commented Mar 24, 2019

More syntax highlighting options can be found here: https://github.com/scopatz/nanorc

You can create a folder called "syntax_improved" inside ~./nano/ and copy all .nanorc files there, then simply extend your .nanorc file to read these new definitions as well with:

include ~/.nano/syntax_improved/*.nanorc

@centminmod
Copy link

centminmod commented Mar 24, 2019

nice or just git clone the lot (syntax highlighting) :)

  mkdir -p ~/.nano
  cd ~/.nano
  git clone --depth=1 https://github.com/scopatz/nanorc syntax_improved
  echo 'include ~/.nano/syntax_improved/*.nanorc' > ~/.nanorc

@arthurdapaz
Copy link

arthurdapaz commented Apr 5, 2019

Now version 6.0 support! (Updated: Jan/11/2021)

Just merged all of your solutions and tips on a single-updated script, also, it doesn't require wget nor brew to be used... Since I made it partially variable-oriented, on future nano versions we will be able to re-use this script... (place and run it from $USER folder)

#!/usr/bin/env bash

# Install Nano (www.nano-editor.org) with syntax highlighting (MacOS)

VERSION="6.0"
NANO_URL="https://www.nano-editor.org/dist/v6"
NANO_SHORT="nano-$VERSION"
NANO_SRC="$NANO_SHORT.tar.gz"
NANO_EXTRA="https://github.com/scopatz/nanorc"

set -e
cd ~/
curl -Ok $NANO_URL/$NANO_SRC
tar -zxvf $NANO_SRC

mv $NANO_SHORT .nano && cd .nano/
./configure && make && sudo make install

git clone --depth=1 $NANO_EXTRA syntax_improved
cd ~/ && touch .nanorc

cat > .nanorc <<EOF
include ~/.nano/syntax/*.nanorc
include ~/.nano/syntax_improved/*.nanorc
EOF

rm -vf $NANO_SRC
printf "\nExit terminal and reopen to start using $NANO_SHORT\nTo uninstall it and revert to old:\ncd ~/.nano && sudo make clean uninstall && rm -rf ~/.nano\n"
exit

Updated:

  • Cleaned up the code
  • Using best practices for bash variables (uppercase)
  • Changed to latest version (4.9.3)
  • Tested on MacOS Mojave 10.14.* (including a hackintosh)
  • Tested on bash v3.* to v5.*
  • Tested on zsh
  • Tested on MacOS Catalina 10.15.5
  • Tested on macOS Big Sur 11.6.2

@fevangelou
Copy link
Author

@arthurdapaz Cool, now it's compatible with both Mac and Linux variants.

@a3igner
Copy link

a3igner commented Apr 10, 2019

@arthurdapaz
i tried your script i get this error:

Error in /Users/andreas/.nanorc on line 2: Error reading ~/.nano/syntax/*.nanorc: No such file or directory

Error in /Users/andreas/.nanorc on line 3: Error reading ~/.nano/syntax_improved/*.nanorc: No such file or directory

even though the directories and files are there.

I changed the order of the way the PATHs are loaded in /etc/paths to load /usr/local/bin before /usr/bin so that the brew version of nano gets loaded before the default OSX version of nano in /usr/bin gets loaded! that fixes that error and it works perfectly now!

@Jvp2001
Copy link

Jvp2001 commented Jun 12, 2019

Thank you very much for this extremely useful script. @arthurdapz

@terasakisatoshi
Copy link

@arthurdapaz
Thank you. it works fine for VERSION="4.3".

I also got error as @a3igner reported.

Error in /Users/andreas/.nanorc on line 2: Error reading ~/.nano/syntax/*.nanorc: No such file or directory
Error in /Users/andreas/.nanorc on line 3: Error reading ~/.nano/syntax_improved/*.nanorc: No such file or directory

My prescription is set alias nano at ~/.bash_profile

alias nano="/usr/local/bin/nano"

It's good to go.

@homogulosus
Copy link

Really nice script. made some fixes for macOS Catalina. works perfect with my setup
Updated to current version as 06/06/2020

#!/usr/bin/env bash

# Install nano editor https://www.nano-editor.org/dist/v4/nano-4.9.3.tar.xz Modified: 2020 May 23 

VERSION="4.9.3"
NANO_SHORT="nano-$VERSION"
NANO_SRC="$NANO_SHORT.tar.xz"
NANO_URL="https://www.nano-editor.org/dist/v4"
NANO_EXTRA="https://github.com/scopatz/nanorc"


cd ~/
wget $NANO_URL/$NANO_SRC
tar -zxvf $NANO_SRC

mv $NANO_SHORT .nano && cd .nano/
./configure && make && sudo make install

git clone --depth=1 $NANO_EXTRA syntax_improved
cd ~/ && touch .nanorc

echo "# Enable syntax highlighting in Nano\ninclude ~/.nano/syntax/*.nanorc\ninclude ~/.nano/syntax_improved/*.nanorc" >> ~/.nanorc

rm -vf $NANO_SRC
print "\nEXit terminal and reopen using $NANO_SHORT\nTo unistall it and revert to old:\ncd ~/.nano && sudo make"
exit

no aliases no path problems. reload your terminal and good to go. at least that was my case.

@a3igner
Copy link

a3igner commented Jun 29, 2020

@homogulosus i just tried this on a fresh catalina install and your script didnt work.

@homogulosus
Copy link

homogulosus commented Jun 29, 2020

#!/usr/bin/env bash

# Install nano editor https://www.nano-editor.org/dist/v4/nano-4.9.3.tar.xz Modified: 2020 May 23

VERSION="4.9.3"
NANO_SHORT="nano-$VERSION"
NANO_SRC="$NANO_SHORT.tar.xz"
NANO_URL="https://www.nano-editor.org/dist/v4"
NANO_EXTRA="https://github.com/scopatz/nanorc"


cd ~/
wget $NANO_URL/$NANO_SRC
tar -zxvf $NANO_SRC

mv $NANO_SHORT .nano && cd .nano/
./configure && make && sudo make install

git clone --depth=1 $NANO_EXTRA syntax_improved
cd ~/ && touch .nanorc

echo "# Enable syntax highlighting in Nano" >> $HOME/.nanorc
echo "include ~/.nano/syntax/*.nanorc" >> $HOME/.nanorc
echo "include ~/.nano/syntax_improved/*.nanorc" >> $HOME/.nanorc

rm -vf $NANO_SRC
printf "\nExit terminal and reopen using $NANO_SHORT\nTo unistall it and revert
to old:\ncd ~/.nano && sudo make\n"
exit

@a3igner It should work fine now, the problem was in the creation of the nanorc

@a3igner
Copy link

a3igner commented Jun 29, 2020

Thanks. I did it already like above and added the alias in the bashrc like suggested above. Works perfectly.

@alexanderblackh
Copy link

#!/usr/bin/env bash

# Install nano editor https://www.nano-editor.org/dist/v4/nano-4.9.3.tar.xz Modified: 2020 May 23

VERSION="4.9.3"
NANO_SHORT="nano-$VERSION"
NANO_SRC="$NANO_SHORT.tar.xz"
NANO_URL="https://www.nano-editor.org/dist/v4"
NANO_EXTRA="https://github.com/scopatz/nanorc"


cd ~/
wget $NANO_URL/$NANO_SRC
tar -zxvf $NANO_SRC

mv $NANO_SHORT .nano && cd .nano/
./configure && make && sudo make install

git clone --depth=1 $NANO_EXTRA syntax_improved
cd ~/ && touch .nanorc

echo "# Enable syntax highlighting in Nano" >> $HOME/.nanorc
echo "include ~/.nano/syntax/*.nanorc" >> $HOME/.nanorc
echo "include ~/.nano/syntax_improved/*.nanorc" >> $HOME/.nanorc

rm -vf $NANO_SRC
printf "\nExit terminal and reopen using $NANO_SHORT\nTo unistall it and revert
to old:\ncd ~/.nano && sudo make\n"
exit

@a3igner It should work fine now, the problem was in the creation of the nanorc

Works on 11.0 Beta 2, thank you!

@oldman20
Copy link

Hello, what’s about nano on IPadOS, sir? I try install this pakage in NewTerm mobile but not working!

@arthurdapaz
Copy link

arthurdapaz commented Sep 20, 2020

Hello, what’s about nano on IPadOS, sir? I try install this pakage in NewTerm mobile but not working!

Does iPadOS even has a terminal? LOL! I'll check this information and the possibility of installing "nano" to a non-jailbroken iOS environment

@husseinnahle
Copy link

husseinnahle commented Sep 22, 2020

@homogulosus i just tried this on a fresh catalina install and your script didnt work.

Try to edit .nanorc file manually and add

# Enable syntax highlighting in Nano
include ~/.nano/syntax/*.nanorc

@Chrisdoan9
Copy link

Hi,

I run the code chunk above on terminal and I got error below. Would anyone please tell me how to fix it? Thank you so much!

Error in /Users/Chris/.nano/syntax_improved/zig.nanorc on line 2: Color "latte" not understood
Error in /Users/Chris/.nano/syntax_improved/zig.nanorc on line 9: Command "tabgives" not understood
Error in /Users/Chris/.nano/syntax_improved/rego.nanorc on line 15: Color "purple" not understood
Error in /Users/Chris/.nano/syntax_improved/Rnw.nanorc on line 19: Bad regex "([a-zA-Z0-9_-$.])(": Invalid range end
Error in /Users/Chris/.nano/syntax_improved/zig.nanorc on line 2: Color "latte" not understood
Error in /Users/Chris/.nano/syntax_improved/zig.nanorc on line 9: Command "tabgives" not understood
Error in /Users/Chris/.nano/syntax_improved/rego.nanorc on line 15: Color "purple" not understood
Error in /Users/Chris/.nano/syntax_improved/Rnw.nanorc on line 19: Bad regex "([a-zA-Z0-9_-$.]
)(": Invalid range end

@fevangelou
Copy link
Author

This script was written for the Bash shell. My guess is you're on Zsh (the new shell used in macOS).

In any case, since this guide was written some time ago, I would recommend installing Homebrew and then just do brew install nano and you're done.

@Chrisdoan9
Copy link

Chrisdoan9 commented May 24, 2022

Hi @fevangelou

I brew install nano then bash and even update to nano 4.0 but I still got that error. I switch from zsh to bash.

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