Installing and Using Nano Text Editor on Linux

Published November 30, 2023

Let’s dive into Installing and Using Nano Text Editor on Linux.

If you’re looking for a command-line environment to create or edit text files, Nano is the way to go. It’s a widely used text editor for Unix and Linux operating systems. Nano is a powerful tool that enables you to effortlessly modify and generate various files.

For those who prefer simplicity, Nano is the perfect choice. It offers all the essential features found in other text editors, including UTF-8 encoding, syntax highlighting, regular expression-based search and replace, multiple buffers, and even spellchecking.

How to install Nano Text Editor on Linux

Nano is a text editor that comes pre-installed on macOS and most Linux variants. Type the following to see whether it’s installed:

Nano — version

As a result, you will see something like this:

GNU nano, version 2.9.3 (C) 1999-2011, 2013-2018 Free Software Foundation, Inc. (C) 2014-2018 the contributors to nano Email: Web: 

Alternatively, the process can be carried out in two stages if necessary.

  • Start by updating the apt repositories using the following command:

sudo apt update

  • After that, install Nano using these commands:

sudo apt install nano


yum install nano

How to Use Nano Text Editor on Linux

Create and open files

To create or open a file, type nano followed by the filename.

nano filename

Ensure that you’re in the correct directory if you want to modify an existing file. Alternatively, you can input the complete file path you’re searching for. Remember, a file must have read rights before you can open it.

nano /path/to/filename

You can write or edit it in the new editor window that opens. The cursor can be moved around the text with the arrow keys on your keyboard. A few shortcuts can be found at the bottom of this window. The ^ symbol means you have to press CTRL + [Key] (CMD + [Key] for Mac users) to execute the command you have chosen.  The file can be saved and edited by pressing CTRL + O. Typing Ctrl + G will also display a list of all commands.  You can exit the editor by pressing CTRL + X. It will ask you whether to save any changes you have made to the file currently open, otherwise it will end the session. Enter Y to indicate yes or N to indicate no, and then press ENTER.

Edit files

Nano is a modeless editor, which means you can start editing right away when you open the file.

To select the text, simply press ALT + A at the beginning of the text. This will mark the text for selection, allowing you to move the cursor over it using the arrow keys.

To copy the selected text, press ALT + 6. This will copy the text to the clipboard, ready to be pasted elsewhere.

If you want to cut the text instead, you can use ALT + K.  When it comes to pasting text, you can use the shortcut CTRL + U. This will paste the text, either copying or cutting the entire line if there is no text selected before copying or pasting.

Remember, if you need to copy the selected text, press ALT + 6. To cut the text, use ALT + K. And for pasting text, the shortcut is CTRL + U.

Exit and save the file

Using the Ctrl+O (^O) keyboard combination, you can save any changes you make in a document. A file name will be required or the name of an existing file will need to be confirmed.A new file will be created once it has been saved.

Press Ctrl+X to exit Nano (Nano displays it as ^X). You will be asked whether you would like to save any changes that have not been saved.

Select, Copy, Cut, and Paste Text

To choose specific sections of a document, go to the start of it and hit Alt+A (M-A). Then, use the arrow keys to move the selection over. This will highlight the chosen area. To undo the selection, press Ctrl+6.

copy the selected text, use Alt+6 or the combination (M-6) and cut it with Ctrl+K (^K). If you don’t select any text before using these shortcuts, the entire line of text will be copied or cut.

When you’re ready to paste the text, press Ctrl+u and place it where you want it.

Replacing and searching text

Use the “where-is” feature of the editor with Ctrl+W (^W) to find a specific word or part of a text. Enter the text you are looking for in the search box. Use Alt+W (M-W) to move on to the next result.

Searching by line number is also possible. You can then find a particular line by pressing Ctrl+T (^T) while in it.  A regex (regular expression) search is also possible.

Regex search patterns are defined by character sequences. You can do this by pressing Alt+R (M-R) on your keyboard.

Use CTRL+W and CTRL+R to find and replace text. Type the text you want to find and the text you want to replace it with. Once the text has been removed, you will be taken to the first instance of the text and asked whether you would like to replace the entire instance or just the first instance.

Navigation shortcuts 

Navigating through a large file quickly is important when working with a large file. Using the arrow keys or keyboard shortcuts is one way to do this in Nano.

  You can navigate using the following keyboard shortcuts: 

  • Ctrl+F (^F) to move one character forward
  • Ctrl+B (^B) to move one character back
  • Ctrl+Space (^Space) to move one word forward Alt+Space (M-Space) to move one word back
  • Ctrl+P (^P) to move to the previous line
  • Ctrl+N (^N) to move to the next line
  • Ctrl+V (^V) to move to the next page
  • Ctrl+Y (^Y) to return to the previous page 
  • Ctrl+A (^A) to move to the beginning of the line
  • Ctrl+E (^E) to move to the end of the line

Nano Spell Check

Nano’s spell-checking feature is also available. This feature requires the spell package to be installed.

Run the following command in the terminal to install the spell package:

sudo apt install spell

Press Ctrl+T (^T) to spell check in the text editor after installing the package. A misspelled word will be highlighted and asked to be replaced.

Nano Text Editor

Read More ;3 Techniques to Rename a Directory in Linux

For more updates follow us on Meta, X, Instagram .