Apr 10, 2023
How to Install and Use Nano Text Editor: A Beginner’s Tutorial
In this tutorial, you will learn how to use and install Nano, a popular text editor of Unix and Linux operating systems. Nano comes with many powerful features and allows you to edit and create various files on your computer or server. So let’s get right to it.
How to Install Nano Text Editor
This process depends on the operating system you are using. Some, like macOS or Linux distros, may already come with the Nano text editor pre-installed.
To check, simply use the following command:
If you see an output that tells you a version number, you can skip this section.
Installing Nano on Debian/Ubuntu
To install Nano text editor on Debian or Ubuntu machines, execute the following command:
sudo apt-get install nano
Then, wait for the installation process to finish.
Important! The sudo part is meant for running this command as a root user. This means you may be prompted to enter a password in case you are currently not logged in as a root user.
Installing Nano on CentOS/RHEL
We can run this command to install Nano text editor on CentOS or RHEL based platforms:
yum install nano
That is it to install Nano. As soon as the setup ends, you can use it immediately.
How to Use Nano Text Editor
In this part, you are going to learn how to open and close files. Also, how to search and replace text. Then, we’ll show you some editing tips and other basic commands that you can use in Nano text editor.
How to Open and Close the Nano Editor
The main syntax to open Nano and to edit a certain file is:
Let’s say we want to open a file named demo.txt. The command would look like:
You can open various file types, like .txt, .php, .html, and so on. Just keep in mind that if you want to open a specific file, you will need to be in the directory where the file is located.
However, if you are in another folder, and you want to open a file (demo.txt) in /path/to/directory, you can enter this line instead:
If you enter a file name and that file is not present in the directory, Nano will create a new file. Meanwhile, if you only execute the nano command without specifying the file name, the Nano text editor will create an empty untitled file and ask for a name when you exit the editor.
After running the nano command, a new window will pop up where you can freely edit the file. Below is what the interface of the Nano text editor looks like. Just use the arrow keys on your keyboard to move the cursor around the text.
At the bottom of the window, you can find some shortcuts to use with the Nano editor. The “^” (caret) means that you must press CTRL (Windows) or control (macOS) to use the chosen command. Here are a few examples.
- Press CTRL + O to save the changes made in the file and continue editing.
- To exit from the editor, press CTRL + X. If there are changes, it will ask you whether to save them or not. Input Y for Yes, or N for No, then press Enter. But if there are no changes, you will exit the editor right away.
Take note that whenever you are opening an important configuration file, it is recommended to use the -w option. It will open the file in a standard format. If you don’t use this option, nano will wrap the text to fit the display by default. The command will be like this:
sudo nano -w /etc/apache2/apache2.conf
How to Search and Replace Text
To search in the text, press CTRL + W. Insert your value and press Enter. To continue searching for the same text string, use ALT + W.
If your goal is to find and replace a text, press CTRL+W and then CTRL+R to enter the text that you want to search and the text that will replace it. The editor will then take you to the first instance of the text. You can press Y to replace one text or A to replace all instances.
Should you want to go back after typing a shortcut, just use CTRL + C to cancel the current process.
How to Edit Text
These are the commonly used shortcuts when editing a text in Nano.
- To select text, go to the beginning of the desired text and press ALT + A. This will set a mark for selecting. Then, you can move over the text with arrow keys.
- Press ALT + 6 to copy the selected text to the clipboard.
- To cut the highlighted text, press CTRL + K.
- If you want to paste the text, navigate to the intended place and press CTRL + U.
Basic Nano Text Editor Commands
We have compiled the most useful commands to help you utilize the Nano text editor more effectively.
|CTRL + A||Lets you jump to the beginning of the line.|
|CTRL + E||Lets you to jump to the end of the line.|
|CTRL + Y||Scrolls page down.|
|CTRL + V||Scrolls page up.|
|CTRL + G||A Help window will pop out and show you all the available commands.|
|CTRL + O||To save the file. Nano will ask you to edit or verify the desired file name.|
|CTRL + W||Search for a specified phrase in your text. Press ALT + W to search for the same phrase again.|
|CTRL + K||It cuts the entire selected line to the cut buffer (similar to clipboard).|
|CTRL + U||To paste the text from the cut buffer into the selected line.|
|CTRL + J||Justifies the current paragraph.|
|CTRL + C||Shows the current cursor position in the text (line/column/character).|
|CTRL + R||Opens a file and inserts it at the current cursor position.|
|CTRL + X||To exit Nano text editor. It prompts a save request if you made any changes to the file.|
|CTRL + \||Replaces string or a regular expression.|
|CTRL + T||Invokes the spell checker, if available.|
|CTRL + _||Lets you go to the specified line and column number.|
|ALT + A||To select text. You can combine this command with CTRL + K to cut a specific part of the text to the cut buffer.|
Why You Should Use Nano Text Editor
When it comes to editing text via command line, Nano is considered one of the easiest tools to use. It beats Vim and Emacs editor, which are known to be overwhelming, especially for novice Linux users.
Though it’s simple, Nano editor packs a complete feature set. To name a few, it allows you to copy, paste, select, and search text. Furthermore, there is a bottom bar inside the editor that shows you useful shortcuts. All in all, the Nano editor is suitable for both advanced users and beginners.
You can often find it prepackaged on Linux PC or server. For example, Hostinger includes Nano text editor on its shared web hosting and VPS plans.
Nano is a popular and versatile terminal-based text editor in Linux. It is a perfect fit for beginners and professionals who are looking for a complete tool to modify their text.
In this tutorial, you have learned how to use the Nano text editor. We have shown you a lot of useful commands and editing tips to improve your workflow. Now, we hope that you can easily edit text without having to download and re-upload the file.
Good luck, and be sure to check our other SSH and VPS tutorials.