Update the nano text editor on Ubuntu

Learn to update the nano text editor using the latest source code release.

Reading time of 572 words
3 minutes
Reading time of 572 words ~ 3 minutes


Did you find this article helpful?
Please consider tipping me a coffee as a thank you.
Ko-fi Buy Me a Coffee
Did you find this article helpful? Please consider tipping me a coffee or three as a thank you.
Tip using Ko-fi or Buy Me a Coffee

In this entry, I will guide you through updating the standard terminal editor used by Ubuntu from its classic 2009 revision to its latest release.

UPDATE: While the article is for Ubuntu 14.04, I've tested these steps in Ubuntu 22.04 with nano 6.4, and it still works. Replace the nano-2.9.3 paths in the instructions, with nano-6.4 or the current edition.

GNU nano is Ubuntu’s default terminal text editor and a fallback editor in case the system fails. It might be one of the reasons why the default nano version gets held back, and you may want to avoid applying this update.

$ nano -V

 GNU nano version 2.2.6 (compiled 14:12:08, Oct 1 2012)
 (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
 2008, 2009 Free Software Foundation, Inc.
 Email: [email protected]    Web: http://www.nano-editor.org/
 Compiled actions: --disable-wraccinc-as-root --enable-color --enable-extra --en

When updating this article in Jan. 2018, a visit to the official GNU nano homepage revealed the current stable nano version is 2.9. At the same time, many Ubuntu installs are running 2.2.6. So let’s update!

Compile and install

First, we remove the existing nano package and install some dependencies we will need to compile nano from source. If you’re curious, the libmagic-dev package is used to auto-detect file types for nano’s syntax highlighting feature.

$ sudo apt-get build-dep nano
$ sudo apt-get install libmagic-dev

Now download the nano source and extract it.

UPDATE: In Oct 2022, current version of nano can be got using:
wget https://www.nano-editor.org/dist/v6/nano-6.4.tar.gz

$ cd ~
$ wget http://www.nano-editor.org/dist/v2.9/nano-2.9.3.tar.gz
$ tar -xf nano-2.9.3.tar.gz
$ cd nano-2.9.3

Run the configuration script, and I apply the following compile option.

$ ./configure --enable-utf8

–-enable-utf8 turns on UTF-8 character encoding support, which is widely in use.

You can see a complete list of options available by using help.

$ ./configure --help

Now compile and install nano. You will see a lot of debugging feedback that you can safely ignore.

$ make
$ sudo apt-get remove nano
$ sudo make install
make install

When complete, let’s test nano to ensure it is installed correctly.

Bash shell users will need to reload .bashrc.

$ source ~/.bashrc
$ nano -V

GNU nano version 2.9.3...

UPDATE:
When writing this article for Ubuntu 14.04, nano v2.9 got installed to: /usr/bin/nano.
In Ubuntu 22.04, make installs nano to: /usr/local/bin/nano.

Change the default settings

The nano install copies a sample settings file into the etc/ directory. We will duplicate this file and apply our custom settings to our home directory.

$ cp ~/nano-2.9.2/doc/sample.nanorc ~/.nanorc
$ nano ~/.nanorc

In nano, tap Ctrl+_+258 to jump to line 258. Un-comment the following text and exit nano.

258# include "/usr/local/share/nano/*.nanorc"
259include "/usr/local/share/nano/*.nanorc"

Reload and edit .nanorc again, but now it will be in colour.

$ nano ~/.nanorc

Go through the .nanorc settings file and un-comment any features you want to be turned on. I enable.

 1set boldtext
 2set constantshow
 3set linenumbers
 4set mouse
 5set smarthome
 6set smooth
 7set titlecolor brightwhite,blue
 8set statuscolor brightwhite,green
 9set selectedcolor brightwhite,magenta
10set numbercolor white
11set keycolor cyan
12set functioncolor green

Save your settings by pressing Ctrl+O, and you are done!

nano nanorc

Uninstall

If you want to revert to the original nano installed by Ubuntu, you can do the following removal.

$ apt-get autoremove nano

You may need to remove the default configuration installed by nano 2.4.2 as it contains invalid directory paths.

$ sudo rm /etc/nanorc

Then install classic nano.

$ sudo apt-get install nano
$ nano -V

GNU nano version 2.2.6...

Written by Ben Garrett

Did you find this article helpful?
Please consider tipping me a coffee as a thank you.
Ko-fi Buy Me a Coffee
Did you find this article helpful? Please consider tipping me a coffee or three as a thank you.
Tip using Ko-fi or Buy Me a Coffee