Introduction
Nano is one of the most popular command-line text editors available on Linux systems. It is lightweight, beginner-friendly, and installed by default on many Linux distributions. System administrators and developers frequently use Nano to edit configuration files, scripts, cron jobs, and server settings directly from the terminal.
In this guide, you’ll learn how to install Nano Editor on AlmaLinux, Rocky Linux, CentOS, RHEL, Ubuntu, and Debian, as well as how to use its most important features efficiently.
What is Nano Editor?
Nano is a terminal-based text editor designed to provide a simple and intuitive editing experience. Unlike Vim or Emacs, Nano does not require memorizing complex commands, making it an excellent choice for beginners and experienced Linux users alike.
Key Features
- Easy-to-use interface
- Lightweight and fast
- Syntax highlighting support
- Search and replace functionality
- Mouse support
- File backup options
- Multi-buffer editing
Installing Nano on AlmaLinux, Rocky Linux, CentOS, and RHEL
Most modern Enterprise Linux distributions use the DNF package manager.
Update Package Repositories
sudo dnf update -y
Install Nano
sudo dnf install nano -y
Verify Installation
nano --version
Example output:
GNU nano, version 7.x
Installing Nano on Ubuntu and Debian
Update Package Index
sudo apt update
Install Nano
sudo apt install nano -y
Verify Installation
nano --version
Opening a File with Nano
To create or edit a file:
nano filename.txt
Example:
nano notes.txt
If the file does not exist, Nano will create it automatically when saved.
Understanding the Nano Interface
When Nano opens, you’ll see:
- File content area
- Status bar
- Shortcut menu at the bottom
The shortcuts displayed use the following notation:
^= Ctrl keyM= Alt key (Meta key)
Example:
^X Exit
^O Write Out
^W Where Is
Basic Nano Commands
Save a File
Press:
Ctrl + O
Then press:
Enter
to confirm the filename.
Exit Nano
Press:
Ctrl + X
If unsaved changes exist, Nano will ask whether to save them.
Cut a Line
Ctrl + K
Paste Text
Ctrl + U
Search Text
Ctrl + W
Enter the search term and press Enter.
Search and Replace
Press:
Ctrl + \
Enter:
- Search string
- Replacement string
Choose whether to replace individual matches or all occurrences.
Go to a Specific Line
Ctrl + _
Enter the line number.
Example:
125
Nano jumps directly to line 125.
Working with Configuration Files
System administrators often use Nano for editing Linux configuration files.
Examples:
SSH Configuration
sudo nano /etc/ssh/sshd_config
Hosts File
sudo nano /etc/hosts
Crontab
crontab -e
You can configure Nano as the default editor if prompted.
Enable Syntax Highlighting
Modern Nano versions support syntax highlighting.
Edit Nano configuration:
sudo nano /etc/nanorc
Uncomment or add:
include "/usr/share/nano/*.nanorc"
Save and restart Nano.
You will now see colored syntax for:
- Bash scripts
- Python
- PHP
- HTML
- CSS
- JavaScript
- JSON
- YAML
- Configuration files
Creating Backup Files Automatically
Edit the Nano configuration file:
nano ~/.nanorc
Add:
set backup
Nano will automatically create backup files whenever changes are saved.
Example:
config.conf~
Display Line Numbers
Add the following to your Nano configuration:
set linenumbers
This is particularly useful when editing scripts and server configuration files.
Useful Nano Keyboard Shortcuts
| Shortcut | Function |
|---|---|
| Ctrl + O | Save file |
| Ctrl + X | Exit Nano |
| Ctrl + K | Cut line |
| Ctrl + U | Paste line |
| Ctrl + W | Search |
| Ctrl + | Search and replace |
| Ctrl + G | Help |
| Ctrl + C | Show cursor position |
| Ctrl + _ | Go to line |
| Alt + U | Undo |
| Alt + E | Redo |
Common Troubleshooting
Nano Command Not Found
If you receive:
nano: command not found
Install Nano using your distribution’s package manager as shown earlier.
Permission Denied
If editing system files:
sudo nano /path/to/file
Administrative privileges are required for protected files.
Nano vs Vim
| Feature | Nano | Vim |
| Beginner Friendly | Yes | No |
| Easy Commands | Yes | Moderate |
| Learning Curve | Low | High |
| Advanced Features | Basic | Extensive |
| Ideal for Quick Edits | Excellent | Good |
For most server administration tasks, Nano is often the fastest editor to use.
Conclusion
Nano remains one of the best text editors for Linux administrators, developers, and beginners. Its simple interface, powerful editing capabilities, and availability across nearly all Linux distributions make it an essential tool for managing configuration files and performing quick edits from the terminal.
Whether you’re running AlmaLinux, Rocky Linux, CentOS, RHEL, Ubuntu, or Debian, Nano provides a reliable and efficient editing environment directly from the command line.
