-
-
Save fevangelou/be744753730e86b8783fd481f311a7c9 to your computer and use it in GitHub Desktop.
#!/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 |
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
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
@arthurdapaz Cool, now it's compatible with both Mac and Linux variants.
@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!
Thank you very much for this extremely useful script. @arthurdapz
@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.
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.
@homogulosus i just tried this on a fresh catalina install and your script didnt work.
#!/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
Thanks. I did it already like above and added the alias in the bashrc like suggested above. Works perfectly.
#!/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!
Hello, what’s about nano on IPadOS, sir? I try install this pakage in NewTerm mobile but not working!
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
@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
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
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.
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.
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: