Installing and Using the Nano Text Editor on Linux
Nano is the easiest editor in a Linux terminal. Install it, open and save files, search and replace, cut and paste, and make it your default editor.
3 min readBy Soumya
Reviewed by the AmazingRDP technical team

A server of your own to practise on. A Linux VPS gives you root access. See Linux VPS from $6.99
Sooner or later every Linux user has to change a configuration file in a terminal. Nano is the editor made for that moment: it opens a file, you type, and the keys you need are listed at the bottom of the screen. There are no modes to learn.
Install
Nano is already present on Ubuntu, Debian and most other systems. If nano --version finds nothing:
| System | Command |
|---|---|
| Ubuntu, Debian | sudo apt install nano |
| Rocky, AlmaLinux, CentOS, Fedora | sudo dnf install nano |
| Arch | sudo pacman -S nano |
Open, save, leave
nano notes.txt
sudo nano /etc/hosts
nano +25 script.sh
The first opens or creates a file. System files need sudo. The third opens a file with the cursor on line 25, which is handy when an error message names a line.
The two lines at the bottom list the commands. ^ means the Ctrl key and M- means Alt.
- Save:
Ctrl + O, then Enter to confirm the file name. (O as in "write Out".) - Leave:
Ctrl + X. If there are unsaved changes, nano asks:Ysaves,Ndiscards.
The keys you will use
| Key | Does |
|---|---|
Ctrl + W | Search; Alt + W finds the next match |
Ctrl + \ | Search and replace |
Ctrl + K | Cut the current line |
Ctrl + U | Paste |
Alt + 6 | Copy the current line |
Alt + A | Start marking text; move the cursor, then cut or copy |
Alt + U / Alt + E | Undo / redo |
Ctrl + _ | Go to a line number |
Ctrl + A / Ctrl + E | Start / end of the line |
Ctrl + Y / Ctrl + V | Page up / page down |
Alt + N | Line numbers on and off (Alt + # on some versions) |
Ctrl + G | Help |
Text copied on your own computer is pasted into nano with the terminal's paste, usually a right-click or Ctrl + Shift + V, not with Ctrl + U.
Useful options
nano -l file.conf
nano -B file.conf
nano -v file.conf
-l shows line numbers, -B keeps a backup copy of the file as it was (with ~ at the end of its name), -v opens read-only.
Settings that last
Create a file named .nanorc in your home folder:
set linenumbers
set tabsize 4
set tabstospaces
set autoindent
set mouse
set softwrap
Each line switches something on for every session: numbers, tab width, spaces for tabs, automatic indentation, mouse clicks to place the cursor, and wrapping of long lines on screen. Syntax colours come from files in /usr/share/nano/ and are usually on already.
Make nano the default editor
Commands such as crontab -e and git commit open "the default editor". If that turns out to be vi and you wanted nano:
echo "export EDITOR=nano" >> ~/.bashrc
sudo update-alternatives --config editor
The first line sets it for your user; the second, on Debian and Ubuntu, sets it for the system. If you are stuck in vi right now: press Esc, type :q! and press Enter.
Edit system files safely
- Make a copy first:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak. - Use the checker a program offers before restarting it:
sudo sshd -t,sudo nginx -t,sudo visudofor the sudo rules. - "Permission denied" when saving means you opened a system file without
sudo. Save it under another name in your home folder, leave, and copy it into place withsudo. See granting sudo access.
Nano or something else?
Nano is right for small edits. For long sessions of programming, people move to Vim or to an editor on their own computer that edits remote files. If you prefer a graphical editor on a server with a desktop, see Notepad++ on Ubuntu Server. Running what you wrote: how to run a shell script.
For a server to practise on, see our Linux VPS plans.
Questions
How do I save and exit in nano?
Press Ctrl + O and Enter to save, then Ctrl + X to exit.
How do I search in nano?
Press Ctrl + W, type the text and press Enter. Alt + W jumps to the next match.
How do I show line numbers in nano?
Start it with nano -l, press Alt + N inside it, or add set linenumbers to ~/.nanorc.
How do I make nano the default editor?
Add export EDITOR=nano to ~/.bashrc, or run sudo update-alternatives --config editor on Debian and Ubuntu.