Don’t like the default text editor on your Linux distro and want to change it to something else? It’s pretty simple to do with a few short commands. I’ll walk you through several ways you can do it, no matter which Linux version you’re using.

For this guide, I’m using Ubuntu 24.04 LTS. If you’re using a different distro, you’re able to still follow along as most if not all the commands are the same.

Running the visudo command to check the default text editor on Linux.

Checking Current Default Text Editor

Before changing the default text editor, it’s good to know the current default one set on your Linux distro. To do that, you can check the $EDITOR variable by running this command:

However, if your $EDITOR variable is not set, you might not get any output in return. If that’s the case, you can also check the default editor using this command:

Changing the default editor on Linux using the select-editor command.

The file was opened inthe nano editor. So, this is my default editor.

Changing the Default Text Editor

Now that you know your current default editor, let’s explore how you can change it.

Using select-editor

The select-editor command lets you select a per-user editor. It selects your preferredsensible-editor. Run the command:

You’ll see several editors listed next to a number. Type in the number for the default editor you want and hit Enter.

Checking the selected_editor file to find the current default editor.

For demonstration, I’m entering 2 to change the default editor toVim. To check if it was successful, run:

It should show you the editor you just selected.

Using the update-alternatives Command

The update-alternatives command lets you maintain symbolic links that determine default commands. you may use this to change default behaviors such as which editor to open for a system call. Unlike the select-editor tool, this is a system-wide selector. To use this command for changing the editor, run:

Then select the number for your preferred editor and press Enter.

Changing the default editor on Linux using the update-alternatives command.

Now, to check if you changed it successfully, run the below command:

In my case, the editor was changed from nano to Vim successfully.

Checking if update-alternatives could change the default editor.

Editing the EDITOR Environment Variable

If the above methods didn’t work for you, or your distro doesn’t support them, then considerconfiguring the necessary environment variables, which I’ll cover in this and the next method.

First, open your shell configuration file in a text editor. Since I’m usingBashon Ubuntu, I’ll be working with the.bashrcfile. In other cases, this could be the bash_profile file or another file depending on your shell. To open the file in nano, run:

Setting the EDITOR environment variable in the bashrc file.

For example, for Vim, the line would be as follows:

If you’re not sure where your editor is located, you may write the line like this:

This method uses thewhich command on Linuxto locate Vim. Once you’ve written the line, save the file with Ctrl+O and then exit nano using the Ctrl+X buttons.

Setting the VISUAL environment variable in the bashrc file.

Here’s a one-liner you’re able to run in your terminal to do the whole thing:

After doing this, you need to make the changes take effect by sourcing the file. To do that, run:

Running the crontab -e command to check the default editor.

Now test if the variable was set properly by running:

It should show the text editor you had just set and use it as default.

Editing the VISUAL Environment Variable

The VISUAL variable’s editor is capable of advanced terminal functionalities and supports full-screen editors such as nano, emacs, vim, etc. The EDITOR variable’s editor doesn’t have such privileges, which makes them a bit different. You can set the VISUAL variable on your shell configuration file the same way you set the EDITOR variable.

See if you’ve successfully set the VISUAL variable.

As expected, that worked successfully.

Testing the Changes

The last thing to do is see if you could successfully change your default text editor to your preferred one. You can check this in a few different ways. For example, you can checkcrontab’s editor. To do so, run:

As you can see, my default text editor is now Vim as opposed to nano.

One important thing to know is that there’s an order of precedence among these configurations. So, suppose that you used different methods to define different default editors. Which will be the default editor? To determine that, here’s the order:

Text editing on Linuxis one of the most common things to do and doing it in your favorite editor is a bonus. If you don’t like the text editors you have on your operating system, you should alsoconsider trying alternativeones.