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
@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