How to Install and Use Nano Text Editor: A Beginner’s Tutorial
access_time
hourglass_empty
person_outline

How to Install and Use Nano Text Editor: A Beginner’s Tutorial

In this tutorial, you will learn how to use Nano, a popular text editor in Linux that comes with many powerful features. It allows you to edit and create various files on your computer or server. So let’s get right into it!

Why You Should Use Nano Text Editor

When it comes to editing text via command line, Nano is considered as the easiest tool 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 hosting and VPS plans.

Before we begin learning how to use Nano, make sure that you have access to a Linux machine and its command line. If you’re testing the steps on a VPS, you also need to know how to establish SSH connection using PuTTY (Windows) or terminal shell (Linux, macOS)

How to Install Nano Text Editor

This process depends on the operating system you are using.  Some of them may already come with the Nano text editor pre-installed. If that is the case, 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

Wait for the installation process to finish.

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 for the installation. 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, search and replace text. Then, we’ll show you some editing tips and other basic commands that you can use in Nano text editor.

Opening and Closing the Nano Editor

The main syntax to open Nano to edit a certain file is:

nano filename

Let’s say we want to open a file named demo.txt. The command would look like:

nano demo.txt.

You can open various file types, like .txt, .php, .html, and so on. Just keep in mind that if you want to specify the file directly, you have to be in the directory where the file is located.

But for example, you are in another folder, and you want to open a file (demo.txt) in /path/to/directory, you should enter this line instead:

nano /path/to/directory/demo.txt

If you enter a name and that file is not present in the directory, Nano will create the file. Meanwhile, if you only execute the nano command without specifying the file name, 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.

The interface of Nano text editor

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 CMD (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 should be like this:

sudo nano -w /etc/apache2/apache2.conf

Searching / Replacing 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.

Editing 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.

CommandExplanation
CTRL + ALets you jump to the beginning of the line.
CTRL + EIt allows you to tump to the end of the line.
CTRL + YScrolls page down.
CTRL + VScrolls page up.
CTRL + GA Help window will pop out and show you all the available commands.
CTRL + OTo save the file. Nano will ask you to edit or verify the desired file name.
CTRL + WIt’s used to search for a specified phrase in your text. Press ALT + W to search for the same phrase again.
CTRL + KIt cuts the entire selected line to the cut buffer (similar to clipboard).
CTRL + UTo paste the text from the cut buffer into the selected line.
CTRL + JJustifies the current paragraph.
CTRL + CShows the current cursor position in the text (line/column/character).
CTRL + ROpens a file and inserts it at the current cursor position.
CTRL + XTo 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 + TInvokes the spell checker, if available.
CTRL + _Lets you go to the specified line and column number.
ALT + ATo select text. You can combine this command with CTRL + K to cut a specific part of the text to the cut buffer.

Conclusion

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.

The Author

Author

Domantas G. / @domantas

Domantas leads the content and SEO teams forward with fresh ideas and out of the box approaches. Armed with extensive SEO and marketing knowledge, he aims to spread the word of Hostinger to every corner of the world. During his free time, Domantas likes to hone his web development skills and travel to exotic places.

Related tutorials

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Become a part of Hostinger now!

More in SSH, VPS
How to Change Permissions and Owners via Command Line

Close