How to install nano text editor in Linux

Nano is a simple, user-friendly command-line text editor for Linux. It is ideal for quick edits to configuration files and is much easier to use than vi/vim for beginners. This article covers installation and basic usage.

Installation

Debian / Ubuntu

sudo apt-get update
sudo apt-get install nano

CentOS / RHEL

sudo yum install nano

Fedora

sudo dnf install nano

Verify installation

nano --version

Opening a file

nano /path/to/file

To open a file and jump to a specific line number:

nano +42 /path/to/file

Basic keyboard shortcuts

nano uses keyboard shortcuts displayed at the bottom of the screen. ^ means Ctrl and M- means Alt.

ShortcutAction
Ctrl+OSave (Write Out)
Ctrl+XExit
Ctrl+KCut the current line
Ctrl+UPaste (Uncut)
Ctrl+WSearch
Ctrl+\Search and replace
Ctrl+GDisplay help
Ctrl+CShow cursor position
Ctrl+_Go to line number
Alt+UUndo
Alt+ERedo

Saving a file

Press Ctrl+O, confirm the filename, then press Enter.

Exiting nano

Press Ctrl+X. If there are unsaved changes, nano will ask whether to save them.

Configuration file

nano's behaviour can be customised in ~/.nanorc (per-user) or /etc/nanorc (system-wide). Useful settings:

set tabsize 4
set autoindent
set linenumbers
set mouse

Enable syntax highlighting by including the default highlight files:

include "/usr/share/nano/*.nanorc"

On this page