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

Typical usage

  1. Open a file:

    nano /path/to/file

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

    nano +42 /path/to/file
  2. Make changes. Move the cursor with the arrow keys and type to insert or edit text.

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

  4. Exit nano. Press Ctrl + X. If there are unsaved changes, nano asks whether to save them.

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
Ctrl + WSearch
Ctrl + \Search and replace
Ctrl + GDisplay help
Ctrl + CShow cursor position
Ctrl + _Go to line number
Alt + UUndo
Alt + ERedo

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