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 --versionOpening a file
nano /path/to/fileTo open a file and jump to a specific line number:
nano +42 /path/to/fileBasic 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 (Uncut) |
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 |
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 mouseEnable syntax highlighting by including the default highlight files:
include "/usr/share/nano/*.nanorc"