How can I get latest version of nano (4.5) on CentOS 7?

Solution 1:

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.

Solution 2:

To get Nano 4 on a CentOS 7 machine it's fairly simple.

  1. Head to and grab the latest .xz (as of February 2020, v4.8 is the latest version).

  2. cd to a suitable directory, e.g. cd /opt.

  3. 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.

  4. Uncompress and untar into a subdirectory named nano-4.8: tar -Jxvf nano-4.8.tar.xz

  5. 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.

  6. Compile: make && sudo make install

  7. 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 with yum remove nano, or nano to nano2 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 use set const this needs updating to set constantshow.

I personally use

set softwrap
set constantshow
include "/usr/local/share/nano/*.nanorc"

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 global nanorc 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

Some other syntax highlighting notes are worth reading on 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 of sh in the one-liner): . 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 to set constantshow anyway.