Nano Text Editor Tutorial, How to Install and Use Nano on Linux
- by Sina Nasiri
- in Tutorials
- View 5853
- Date 14 Dec, 20
Short on time? Here are the shortcuts you'll actually reach for 95% of the time. Bookmark this section — the rest of the article fills in the context.
Nano Quick Cheat Sheet (Top Nano Shortcuts)
| Shortcut | What it does | Notes |
|---|---|---|
Ctrl+O |
Save in nano (Write Out) | Press Enter to confirm the filename |
Ctrl+X |
Exit Nano | Prompts to save if there are unsaved changes |
Ctrl+K |
Cut the current line | Select a region first for partial cuts |
Ctrl+U |
Paste in Nano | Pastes whatever was last cut or copied |
Alt+6 |
Copy the current line or selection | Some terminals intercept Alt — see the troubleshooting section |
Ctrl+W |
Search nano (Where Is) | Alt+W jumps to the next match |
Ctrl+\ |
Search and Replace | Prompts for search term, then replacement |
Ctrl+_ (Ctrl+Shift+-) |
Go to line and column | Enter line,column (e.g. 42,1) |
Ctrl+T |
Spell check | Requires aspell or hunspell installed |
Ctrl+R |
Read another file into the current buffer | This is not split-screen — see the multi-file section |
Ctrl+G |
Show the full help menu | Useful when you forget a shortcut mid-edit |
Alt+U / Alt+E |
Undo / Redo | Works across your entire edit session |
Want the printable version? Grab the PDF cheat sheet at the bottom of this guide — it's sized for a single page so you can pin it next to your monitor.
What is Nano, and Why Use It?
Nano is the "just open the file and type" text editor for the Linux terminal. No modes. No 40-page learning curve. You open a file, edit it, save it, done.
If you've ever tried Vim and ended up stuck in it (we've all been there), Nano is the relief valve. It shows its main shortcuts at the bottom of the screen at all times, which sounds like a small thing but it genuinely changes how fast a beginner can get productive.
Here's the quick comparison most people want:
| Editor | Learning curve | Best for | Pre-installed on |
|---|---|---|---|
| Nano | Minutes | Config edits, quick fixes, SSH sessions on unfamiliar boxes | Most Ubuntu, Debian, and many cloud VPS images |
| Vim | Weeks | Power users, developers who live in the terminal | Almost every Linux distro (as vi or vim) |
| Emacs | Months (it never really ends) | Serious customization, lisp enthusiasts | Usually optional install |
My honest take after years of SSH'ing into servers: I still use Nano for 80% of config-file edits on remote boxes. It's fast, forgiving, and I never have to explain to a junior engineer how to exit it. That's worth a lot.
Install Nano on Any OS (Copy-Paste Commands)
Nano ships by default on most modern Linux systems, but not all. Here's how to install or verify it on the common ones.
First, check if it's already there:
nano --version
If you see something like GNU nano, version 7.2, you're done. If the shell says "command not found," pick your OS below.
Debian / Ubuntu (and derivatives like Mint, Pop!_OS)
sudo apt update
sudo apt install -y nano
RHEL / CentOS / Rocky / AlmaLinux
On older RHEL-family systems you'll use yum. Newer ones (8+) use dnf — both commands work, though, because dnf aliases yum.
sudo dnf install -y nano
# or on older systems:
sudo yum install -y nano
Fedora
sudo dnf install -y nano
Arch Linux / Manjaro
sudo pacman -S nano
Alpine Linux (common in Docker)
apk add nano
macOS
macOS ships with an ancient Nano (version 2.0.6 on most builds). If you want the modern version with syntax highlighting defaults that don't feel stuck in 2008, install via Homebrew:
brew install nano
Then restart your terminal or run hash -r so your shell picks up the new binary.
Windows (WSL or Chocolatey)
Honest advice: don't fight Windows on this. Install WSL and run Nano there:
wsl --install -d Ubuntu
# then inside the Ubuntu shell:
sudo apt install -y nano
If you really need it natively, you can use Chocolatey or the Windows port from the GNU Nano project, but the experience is rougher. I'd just use WSL.
Termux (Android)
pkg install nano
Yes, Nano runs fine on a phone. I've edited Nginx configs from a train platform more than once. Not recommended, but possible.
Opening and Creating Files
The basics are dead simple. To open or create a file, run:
nano filename.txt
If the file exists, Nano opens it. If it doesn't, Nano opens a blank buffer and creates the file the moment you save.
Opening by full path works too:
nano /etc/nginx/nginx.conf
Two flags worth knowing right away:
nano -l filename— opens the file with line numbers visible on the side.nano +42 filename— opens the file and jumps straight to line 42. Saves you aCtrl+_.nano -B filename— creates a backup (filename~) when you save. Good habit on production configs.
About that bottom menu: those cryptic ^X and M-U symbols at the bottom of the screen mean Ctrl+X and Alt+U (or the Meta key on old keyboards). The caret is shorthand for Ctrl. The M- prefix is shorthand for Meta, which on modern keyboards is Alt. Once you see that, the whole menu stops feeling like hieroglyphics.
Essential Nano Commands (With Real Examples)
Save and Exit
Press Ctrl+O to save. Nano asks you to confirm the filename — just hit Enter unless you want to save under a different name. Then press Ctrl+X to exit.
If you try to exit with unsaved changes, Nano asks "Save modified buffer?" — type Y to save, N to discard, or Ctrl+C to cancel and go back to editing. Simple.
Copy, Cut, and Paste
This trips people up more than it should, because the terminology is a little off from what you expect. Here's the workflow:
- Move the cursor to the start of the text you want to select.
- Press Alt+A (or Ctrl+^ on some systems) to set a "mark" — the selection anchor.
- Use the arrow keys to move to the end of your selection. You'll see the text highlight as you go.
- Press Alt+6 to copy, or Ctrl+K to cut.
- Move to where you want to paste, then press Ctrl+U.
Quick tip: if you just want to cut a whole line, skip the mark entirely. Put the cursor anywhere on the line and press Ctrl+K. Nano grabs the whole line. Press it again to stack more lines into the clipboard.
Search and Replace
Here's a concrete example. Say you have this file:
server_name example.com;
root /var/www/example.com;
access_log /var/log/nginx/example.com.log;
You want to replace all instances of example.com with monovm.com. Here's how:
- Press Ctrl+\. A prompt appears: "Search (to replace):"
- Type
example.comand press Enter. - Another prompt asks "Replace with:" — type
monovm.comand press Enter. - Nano jumps to the first match and asks "Replace this instance?". Press Y to replace one, N to skip, or A to replace all.
For a plain search (no replace), press Ctrl+W instead. Then Alt+W jumps to the next match.
One thing beginners miss: Nano's search supports regex. Turn it on mid-search by pressing Alt+R at the search prompt. Useful when you need to match patterns like ^\s*# (commented config lines).
Go to a Specific Line
Press Ctrl+_ (that's Ctrl plus the underscore key, which usually means Ctrl+Shift+-). Nano prompts for the line number. You can also pass both line and column separated by a comma, like 120,15.
Spell Check
Press Ctrl+T to spell check the current buffer. This only works if you have aspell or hunspell installed. On Ubuntu:
sudo apt install -y aspell aspell-en
Without the spell checker binary, Ctrl+T will throw an "external command not found" error. That's the usual confusion.
Working with Multiple Files and Buffers
Here's where I need to correct something you'll see in a lot of old Nano tutorials floating around the web: Nano does not have a true split-screen mode. It never has. Articles that tell you to press Ctrl+R to split horizontally are wrong — Ctrl+R actually reads another file and inserts its contents into your current buffer at the cursor position. That's a different feature.
What Nano does support is opening multiple files as separate buffers:
nano file1.conf file2.conf file3.conf
Then switch between them with Alt+> (next buffer) and Alt+< (previous buffer). Simple, and honestly good enough for most editing tasks.
If you really need actual side-by-side editing, use tmux or screen — open Nano in each pane. That's the standard workflow on remote servers.
Configure Nano with nanorc (Syntax Highlighting, Line Numbers, and More)
Out of the box, Nano is pretty barebones. The moment you add a ~/.nanorc config file, it becomes a different animal — syntax highlighting, persistent cursor position, soft wrapping, the works.
Create or edit your personal config:
nano ~/.nanorc
Here's a solid starter config that I use on every server I work on:
# Show line numbers in the gutter
set linenumbers
# Don't wrap long lines — just scroll sideways
set nowrap
# Tab size of 4 spaces, convert tabs to spaces
set tabsize 4
set tabstospaces
# Remember cursor position between edits
set positionlog
# Allow mouse clicking inside the terminal
set mouse
# Show the cursor position constantly (line and column)
set constantshow
# Enable syntax highlighting for all supported languages
include "/usr/share/nano/*.nanorc"
Save with Ctrl+O, exit with Ctrl+X, and the next time you open Nano you'll see the difference immediately.
Adding Syntax Highlighting for Languages Not in the Default Pack
The /usr/share/nano/ directory only ships with highlighting rules for the most common languages. If you need something niche (Rust, Go, YAML variants), you can pull community-maintained files from the scopatz/nanorc repo on GitHub and include them the same way:
git clone https://github.com/scopatz/nanorc.git ~/.nano
echo 'include "~/.nano/*.nanorc"' >> ~/.nanorc
Restart Nano. You now have highlighting for over 100 languages.
Advanced Tips Worth Knowing
Edit System Files Safely
When you need to edit /etc/fstab or anything under /etc/, the instinct is to run sudo nano /etc/fstab. That works, but it has a subtle downside: Nano runs as root, so it reads your root user's ~/.nanorc, not yours. Your nice config gets ignored.
A safer pattern, especially on shared servers, is sudoedit:
sudoedit /etc/fstab
This opens the file in your user's editor (you can set this via the EDITOR environment variable), copies it to a temp location, and only writes changes back to the protected file after you close the editor. Safer, cleaner, and your config still applies.
To make Nano your default editor for sudoedit and other tools:
echo 'export EDITOR=nano' >> ~/.bashrc
source ~/.bashrc
Fix Encoding Issues the Right Way
If a file looks like garbled nonsense in Nano, it's almost always a character encoding mismatch — not a Nano bug. Nano assumes UTF-8. If your file is Latin-1 or Windows-1252, you'll see mojibake.
Don't use the -c flag to fix this (some old tutorials suggest it — they're wrong; -c shows the constant cursor position indicator, it has nothing to do with encoding). Instead, convert the file with iconv:
iconv -f WINDOWS-1252 -t UTF-8 oldfile.txt -o newfile.txt
Then open newfile.txt in Nano and you'll see proper characters.
Recover from a Crash or SSH Drop
If your SSH connection drops mid-edit or the terminal closes, your unsaved changes are gone — Nano doesn't write swap files by default. But if you ran Nano with the -B flag, there's a backup file sitting next to the original (named filename~) containing the version before your last save. Small comfort, but it's saved me more than once.
For real safety on long editing sessions, always run Nano inside tmux or screen so the session survives disconnects.
Troubleshooting: Quick Fixes for Common Problems
These are the six issues that come up most often in support tickets.
1. "Permission denied" when saving
You opened the file without enough privileges. Either reopen with sudo:
sudo nano /etc/hosts
Or save to a path you own (your home directory) and move it with sudo afterward. If you find yourself doing this constantly on system files, switch to sudoedit — covered in the Advanced Tips section above.
2. Keyboard shortcuts aren't firing (Alt+6 does nothing, etc.)
Your terminal emulator is intercepting the keystroke before it reaches Nano. Common culprits: GNOME Terminal, iTerm2, Windows Terminal, tmux default keybindings. Check your emulator's keybinding preferences and either remap the conflicting shortcut or use the Esc key as an Alt substitute (press Esc, release, then press the second key — Nano accepts this as a Meta sequence).
3. "Error writing filename: No space left on device"
The disk is full. Check with:
df -h
Clear some space (old logs in /var/log/ are usually the culprit on small VPS instances) and try saving again. If you're running low on storage regularly, it might be time to look at upgrading your VPS plan.
4. Nano is slow on a huge file
Nano loads the entire file into RAM. On files over a few hundred MB, it struggles. For those, reach for less to view, or sed / awk to edit in place without loading everything.
5. Line numbers aren't showing up
Either add set linenumbers to your ~/.nanorc (described above), or just launch Nano with nano -l filename for a one-off.
6. Nano freezes or crashes mid-edit
Rare, but it happens — usually when editing a file that's been corrupted or has strange binary content mixed in. Two things to try:
- If Nano hangs but the terminal still responds, press Ctrl+C to cancel any in-progress operation (like a long search). That fixes it 90% of the time.
- If it's genuinely locked up, open the file in
less filenamefirst to check what you're dealing with. Iflessshows garbled binary data, you shouldn't be opening it in Nano anyway — usehexdumporxxdfor binary inspection.
The habit that saves you from all of this: save every few minutes with Ctrl+O. Nano doesn't autosave. If you're SSH'd into a remote server, run Nano inside tmux so your session survives disconnects.
Nano Alternatives: When to Reach for Something Else
Nano is great at what it does — quick edits, config files, zero learning curve. But it's not the right tool for every job. Here's an honest rundown of when you should pick something else, based on what I've seen work in real production environments.
Vim (or Neovim)
The obvious upgrade path. Vim is modal, which is what scares off beginners, but that same modality is what makes it stupidly fast once you internalize it. You stop moving your hands to the mouse or the arrow keys — everything is a keystroke away.
Pick Vim when: you're doing serious code editing in the terminal, working with huge files that make Nano sluggish, or you SSH into servers for a living and want an editor that'll be there on every Linux box you ever touch.
Skip Vim when: you need to fix a config file in the next 30 seconds and you haven't learned it yet. The learning curve is real — plan on a few weeks before you stop fighting it.
Install:
sudo apt install -y vim # Debian/Ubuntu
sudo dnf install -y vim # Fedora/RHEL
brew install vim # macOS
If you want a modern take on Vim with better defaults, Lua config, and an active plugin ecosystem, look at Neovim (nvim). Most power users I know switched years ago.
Emacs
Emacs is less a text editor and more a programmable environment that happens to edit text. People use it to read email, manage their calendar, run a terminal, and yes — write code. It's powerful in ways that genuinely feel unreasonable once you've lived in it.
Pick Emacs when: you want one tool to do everything, you're comfortable with Lisp, or you work on large projects where org-mode and magit (the git interface) will change your life.
Skip Emacs when: you just want to edit a file. The investment isn't worth it for casual use. And on most servers it's not preinstalled, so you'll be fighting uphill from minute one.
Micro
This is the hidden gem nobody talks about enough. Micro is like Nano with better defaults — it uses the keybindings you already know from GUI editors (Ctrl+S to save, Ctrl+C/Ctrl+V for copy-paste, Ctrl+Z to undo). It has syntax highlighting out of the box, mouse support, split panes (actual ones), and a plugin system.
Pick Micro when: Nano feels too limited but Vim is overkill. This is my pick for anyone coming from VS Code or a GUI editor who now has to work in a terminal.
Install:
sudo apt install -y micro # Debian/Ubuntu 20.04+
sudo dnf install -y micro # Fedora
brew install micro # macOS
Honestly, if Micro had been preinstalled on every server the way Nano is, I'd probably have switched years ago.
VS Code with Remote SSH
Not a terminal editor — but worth mentioning because this is how a lot of modern dev work actually happens. VS Code's Remote SSH extension lets you open files on a remote server in your local VS Code instance. You get full IDE features against remote files as if they were local.
Pick this when: you're editing code on a dev server regularly, not just tweaking configs. You get IntelliSense, linting, a debugger, git integration — the whole IDE experience.
Skip this when: you only have SSH access through a jump host, the server is locked down tight, or you just need to change one line in /etc/nginx/nginx.conf. For that, Nano still wins.
ed, sed, and awk (honorable mentions)
For completeness: ed is the original Unix line editor (yes, it's still installed on most systems). sed and awk aren't interactive editors at all — they're command-line tools for scripted text manipulation. You won't use ed intentionally in 2026, but you'll reach for sed and awk constantly once you get comfortable with them.
# Replace "foo" with "bar" everywhere in a file, in-place
sed -i 's/foo/bar/g' filename.conf
# Print only lines matching a pattern
awk '/ERROR/ {print $0}' /var/log/app.log
Quick comparison
| Editor | Learning curve | Best for | Preinstalled on most servers? |
|---|---|---|---|
| Nano | Minutes | Config edits, quick fixes | Yes |
| Vim / Neovim | Weeks | Heavy terminal coding, huge files | Vim: yes. Neovim: no |
| Emacs | Months | All-in-one environment | No |
| Micro | Minutes | GUI editor refugees in the terminal | No |
| VS Code + Remote SSH | Already know it | Full IDE workflow on remote code | N/A (local) |
My honest advice after years of this: learn Nano well enough to handle any config-file emergency, then invest in learning Vim for the long haul. That combo covers 95% of what you'll ever need from a terminal editor. Everything else is preference.
Printable Cheat Sheet and Downloads
I put together a one-page PDF with every shortcut from this guide, laid out by category. Print it, tape it to your monitor, send it to a teammate who's new to Linux — whatever works.
Download the Nano Cheat Sheet (PDF)
You can also find all the example ~/.nanorc configs from this article in a single gist linked from the download page.
Where to Go From Here
If this is your first real encounter with the Linux terminal and Nano was your way in, congrats — you've just cleared the hurdle that trips up most beginners. But Nano is one small tool in a much bigger toolbox. File permissions, sudo, shell scripting, services, systemd, package managers — there's a lot more ground to cover before you're genuinely comfortable running a Linux box.
If you want a structured path from "I just learned Nano" to "I can actually administer a Linux server," I put together a complete roadmap over here: How to Learn Linux (the Practical Roadmap). It covers the commands and concepts that matter in roughly the order you should learn them, with no pretending you need to read a 600-page book first.
A few things worth tackling right after Nano:
- Basic file operations —
cp,mv,rm,ls -la,find,grep. These do 80% of the work you'll ever do in a terminal. - Permissions and ownership —
chmod,chown, understanding what 755 vs 644 actually means. This is where most "permission denied" errors come from. - Package management — how to install, update, and remove software on your distro (apt, dnf, or pacman depending on what you're running).
- SSH and sudo — how to log into remote servers securely and run commands with elevated privileges without making a mess.
Work through those four and you'll stop feeling like the terminal is a foreign country. From there, shell scripting and systemd are the natural next steps.
Test Nano on a Real Server
If you're learning Nano, the fastest way to get comfortable is to spin up a fresh Linux VPS and just break things in a sandbox. A basic Linux VPS from MonoVM gives you a clean environment where you can edit config files, practice sudo editing, test your nanorc setup, and not worry about wrecking your main machine. Plans start at a few dollars a month and come preloaded with Ubuntu, Debian, or CentOS — Nano included.
For Linux Users
Create a File in Nano Text Editor
- To create a new file or open the existing file, type Nano, and write the file's name in it. For example, type nano filename and execute it for further actions.
- After executing the command, the system will open another editor window to create or edit your file.
- You will see a list at the bottom of the editor's window, so this list has basic command shortcuts of nano editor.
- All of the commands are prefixed by "^" or "M" because "^" works as the Ctrl key, and "M" works as an Alt key.
- If you want to see this list manually, then you can type Ctrl+g for it.
Editing Files in Nano Text Editor
- Nano text editor offers a modeless editor that means you can type and edit a text quickly after opening a file.
- For moving a cursor to a particular line or character number, you need to use the Ctrl+_
- This command will change the menu at the button of the window, so enter the number in the field of "Enter line number, column number:" then press the enter button.
Search or Replace a Text
- For searching a text in the file, you need to press Ctrl + W keys, type the text in the search box and press the Enter button.
- After the successful execution of the command, the cursor automatically moves that particular text. Press Alt and W keys to move to the next similar text.
- To replace a text in the file, you need to press Ctrl + \ keys and then enter the search term with the text.
- After executing the above step, the editor cursor moves to that particular text then asks for replacement.
- This cursor will move to the next matching text once the user press the Y or N keys on your keyboard. On pressing A on your keyboard, the editor will replace all of the matching texts.
Copy, Cut or Paste
- For selecting a text, move the cursor on the text then press the Alt + A keys to create a selection mark.
- Next, move the cursor to the end of that text for selecting it by using arrow keys, and the selected text will be highlighted after it.
- Now, copy that particular text by using Alt + 6 or use Ctrl + K to cut that particular text.
- Finally, move the cursor to a particular press and press Ctrl + U to paste that particular copied text.
Q. Let us know in the comments below what command was used to get the above result?
Save and Exit
- As we have described creating a file, you have to save it to make successful changes or modifications in the file. So, press Ctrl and O to save the file easily.
- If you want to exit a file, press Ctrl and X, but it will ask you to save changes if there are any unsaved change in the file.
For Windows Users
Open Nano Text Editor
- First, open the command prompt in the system and type Nano (You may want to download and install the Nano text editor before this procedure). You can also try using the nano /path/to/filename to open it.
- It will open a new window of the Nano text editor, in which you will see various options at the top of that window.
- There is a complete list of shortcut keys that you can use to obtain the results for this text editor.
Copy, Cut, and Paste
- If you copy or cut a text, then highlight it with the cursor, or you can mark that through the Ctrl + ^.
- If you want to cut that particular text, use Ctrl + K to cut it or use Alt + ^ to copy it.
- For pasting a particular text at any place, move the cursor to that space and use Ctrl + U for pasting it. These shortcuts become handy and helpful while working on the configuration file in the Nano text editor.
Conclusion
This article provides all of the information that helps you use the Nano text editor. As we have stated above, many users prefer emacs or vim as a text editor, but these are advanced-level editors that require higher skills and knowledge to obtain the desired output. Therefore if you are a new user or a beginner, you can go for the Nano text editor due to its features.
This article will help you to understand how to create and edit a file quickly without having any errors in the Nano Text Editor. So, go ahead and get started, and come back and leave feedback if you found this article helpful.
Sources and Further Reading
- Official GNU Nano manual — the canonical reference for every flag and shortcut
- GNU Nano cheatsheet — the project's own quick reference
- scopatz/nanorc — community syntax highlighting files for 100+ languages
- Ubuntu Community Nano guide — distro-specific notes and tips
- MonoVM Blog — more Linux admin and VPS tutorials
Category: Tutorials