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 nanoCentOS / RHEL
sudo yum install nanoFedora
sudo dnf install nanoVerify installation
nano --versionTypical usage
-
Open a file:
nano /path/to/fileTo open a file and jump to a specific line number:
nano +42 /path/to/file -
Make changes. Move the cursor with the arrow keys and type to insert or edit text.
-
Save the file. Press Ctrl + O, confirm the filename, then press Enter.
-
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.
| Shortcut | Action |
|---|---|
Ctrl + O | Save (Write Out) |
Ctrl + X | Exit |
Ctrl + K | Cut the current line |
Ctrl + U | Paste |
Ctrl + W | Search |
Ctrl + \ | Search and replace |
Ctrl + G | Display help |
Ctrl + C | Show cursor position |
Ctrl + _ | Go to line number |
Alt + U | Undo |
Alt + E | Redo |
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 mouseEnable syntax highlighting by including the default highlight files:
include "/usr/share/nano/*.nanorc"