How to install Nano Text Editor

In this tutorial, you will learn how to use and install Nano Text Editor, a popular text editor for Unix and . Nano comes with many powerful features and allows you to edit and create various files on your computer or server. So let’s learn more below.

How to install Nano Text Editor

This process depends on the operating system you are using. Some versions, like macOS or Linux, may already come with the Nano text editor pre-installed.

To verify it, simply use the following command:

nano –version

If you see the output telling you a version number, you can skip the next section.

Install Nano Text Editor on Debian/Ubuntu

To install Nano Text Editor on Debian or Ubuntu machines, run the following command:

sudo apt-get install nano

Then wait for the installation process to finish.

The part sudo is meant to run this command as the root user. This means that you may be prompted to enter a password if you are not currently logged in as root.

Install Nano on CentOS/RHEL

We can run this command to install Nano Text Editor on CentOS or RHEL based platforms:

yum install nano

That’s it, that’s how easy you can install Nano. As soon as you finish the setup, you will be able to use it right away.

How to use NanoText Editor

In this part, you will learn how to open and close files. Also, how to find and replace text. Then we’ll show you some editing tips and other basic commands you can use in the Nano text editor.

How to open and close the Nano Editor

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

nano filename

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

nano demo.txt

You can open various types of files, such as .txt, .php, .html, etc. Just keep in mind that if you want to open a specific file, you’ll need to be in the directory where the file is located.

See also  How to Install WordPress? (, PC and Mac) - Explanatory Video

However, if you are in another folder and want to open a file (demo.txt) in /path/to/directory, for example, you can enter this line of code:

nano /path/to/directory/demo.txt

If you enter a file name and that file is not present in the directory, Nano will create a new file. But, if you just run the nano command without specifying the file name, the Nano text editor will create an empty untitled file and prompt you for a name when you exit the editor.

After executing the command elder brother, a new window will appear where you can freely edit the file. Below is how the Nano text editor interface looks like. Simply 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 you should press CTRL (on Windows) or control (on macOS) to use the chosen command. Here are some examples.

  • press CTRL + O to save the changes made to the file and continue editing.
  • To exit the editor, press CTRL + X. If there are changes, it will ask you if you want to save them or not. enter Y for Yeseither N for Nopethen press Enter. But if there are no changes, you will exit the editor immediately.

Note that whenever you open an important configuration file, it is recommended to use the option -w. The file will open in a standard format. If you don’t use this option, nano will stretch the text to fit the screen by default. The command is as follows:

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

How to find and replace text

To search the text, press CTRL + W. Insert the value and press Enter. To continue searching for the same text string, use ALT + W.

If your goal is to find and replace text, press CTRL + W and then CTRL + R to enter the text you want to search for and the text to replace it. The editor will take you to the first instance of the text. you can press Y to replace a text or A to replace all instances.

See also  How to install and configure Docker on Ubuntu 18.04

If you want to go back after typing a shortcut, just use CTRL + C to cancel the current process.

How to edit a text

These are the commonly used shortcuts when editing text in Nano.

  • For select textgo to the beginning of the desired text and press ALT + A. This will set a mark to select. You can then move over the text with the 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 desired place and press CTRL + U.

Basic Nano Text Editor Commands

We have put together the most useful commands to help you use the Nano text editor more effectively.

Command
Explanation

CTRL + A
Go to the beginning of the line

CTRL + E
Go to the end of the line

CTRL + Y
download in file

CTRL + V
upload in file

CTRL + G
A Help window will appear and show you all the available commands.

CTRL + O
Save the file. Nano will ask you to edit or verify the name of the desired file.

CTRL + W
It is used to search for a text within the file. press ALT + W to search for the same phrase again.

CTRL + K
Cut an entire line from the file (similar to clipboard)

CTRL + U
Paste the line cut with the above command

CTRL + J
Justify the paragraph

CTRL + C
Shows the current position of the cursor in the text (line/column/character)

CTRL + R
Opens a file and inserts it at the current cursor position.

CTRL + X
To exit the Nano text editor. Make a save request if you made any changes to the file.

CTRL + \
Replace a line or regular expression

CTRL + T
Shows the dictionary and spell checker, if available.

See also  git files

CTRL + _
Go to a specific row and column

ALT + A
To select text. You can combine this command with CTRL + K to cut a specific part of the text.

Why you should use Nano Text Editor

When it comes to editing text via command lines, Nano is considered one of the easiest tools to use. It’s better than the editor and , which are known to be overwhelming, especially for beginner Linux users.

Although simple, the Nano editor packs a full set of features. To name a few, it allows you to copy, paste, select and search for text. Also, there is a bottom bar inside the editor that shows useful shortcuts. With all this, the Nano editor is suitable for both advanced users and beginners.

You can often find it pre-packaged on a Linux PC or server. For example, includes a Nano text editor in its and .

conclusion

Nano is a very popular and versatile command line based text editor for Linux. It is perfect for beginners and professionals 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 many useful commands and editing tips to improve your workflow. Now we hope that you can easily edit the text without having to download and re-upload the file.

Good luck and be sure to check out our other tutorials on and .

Gustavo is passionate about creating websites. He focuses on the application of SEO strategies at for Spain and Latin America, as well as the creation of high-level content. When he is not applying new WordPress tricks you can find him playing the guitar, traveling or taking an online course.

Loading Facebook Comments ...
Loading Disqus Comments ...