The latest version of the nano editor is 4.5 (https://www.nano-editor.org/)... I'm running 2.3.1 on my CentOS 7 server and want to upgrade. But no repos (EPEL, Remi, etc.) seem to have anything newer than 2.3.
How can I get the latest nano? Do I need to build it from scratch on the server? I'd rather be able to use yum
to manage installs/upgrades, if possible.
I see lots of download options (packages, Open SUSE[?], distributions, blah blah) on the nano page but none of them seem to be the right thing for yum. I think.
To get Nano 4 on a CentOS 7 machine it's fairly simple.
Head to https://www.nano-editor.org/dist/v4/ and grab the latest .xz (as of February 2020, v4.8 is the latest version).
cd
to a suitable directory, e.g.cd /opt
.Make a subdirectory to store everything:
mkdir -p /opt/apps/nano
As some people do, you can also download the matching GPG signature and verify it.
Uncompress and untar into a subdirectory named
nano-4.8
:tar -Jxvf nano-4.8.tar.xz
CD to the extracted folder and run configure:
cd nano-4.8 && ./configure
.You may need to install ncurses; read the output of
make
and it will advise you if so.Compile:
make && sudo make install
Tidy up and symlink the
nano
binary (if you didn't specify install location during configuration).This method could be improved but overall I'm happy with it.
By default, the configure script points the eventual install to the default location of
/usr/local/bin
. You can customise with the--prefix=PREFIX
(where PREFIX is an absolute file path) passed to./configure
but I don't mind the default. More info's available with./configure --help
.My machine doesn't include
usr/local/bin
in$PATH
; for an easy life you can uninstall nano 2 withyum remove nano
, ornano
tonano2
and install a symlink if you want to keep both for reasons:mv /bin/nano /bin/nano2
ln -s /usr/local/bin/nano /bin/nano
After doing this, note that some
.nanorc
config variables have changed, so if you useset const
this needs updating toset constantshow
.I personally use
The include enables syntax colouring and the other two are self-evident. Nano 4 now softwraps by default but I've left it in.
softwrap is beneficial, you'll avoid inadvertently inserting line breaks in files with lines breaking over the width limit).
You can define these in
~/.nanorc
or do it globally via the globalnanorc
file. (location varies).The one thing I've not been able to figure out is where this global config should go - the usual paths like
/etc
,/etc/default
,/usr/local/etc
, and so on, don't work.strace -e open nano
shows nano is not even attempting to open a global config file in any of the common locations. Maybe it needs another flag specified at compile time, but nothing obvious sticks out on./configure --help
though. The docs also changed after version 3 and vaguely refer to a system-wide config file whose location varies.It seems that compiling from source by default doesn't include a global config. I just use my
~/.nanorc
and include the syntax highlighting files from there, works fine. Perhaps investigating the version compiled for the repo RPM would reveal what needs changing.A full list of options for
nanorc
is available in the docs (man nanorc
or at https://www.nano-editor.org/dist/v4/nanorc.5.html).Some other syntax highlighting notes are worth reading on https://www.mc-guinness.co.uk/blog/20160307/configuring-nano-text-editor-in-ubuntu/ and a few other posts on SE, AskUbuntu etc.
Edit, Feb 2020: I've used scopatz' syntax highlighting auto-install script in 'lite' mode (
sh -l
instead ofsh
in the one-liner): https://github.com/scopatz/nanorc . Other syntax highlighting packs are available.I also had to comment out
set const
as that particular syntax is deprecated, and nano 4 softwraps by default. As of nano 2.7 the syntax changed toset constantshow
anyway.EL 7 packages were established a few years ago, and their builds are still at 2.3 because it is a stable distro. Many repos will not replace packages from base EL.
To continue using a Red Hat RPM, consider upgrading the OS of your editor environment (could be a VM or a container).
EL 8 appears to be up to 2.9, based on the CentOS 8 nano.spec and the packages on the mirrors. Not the latest.
Fedora 30 is newer, 4.2.
Or, feel free to compile yourself, perhaps take the Fedora spec and rebuild. As usual, you take on more responsibility if building yourself.
According @Chris Woods answer - i made one line script (nano version 5.9)
You can't. Nano 4.5 has dependencies on packages that are not available in CentOS 7 repos. If you want bleeding edge with that CentOS feeling, use Fedora