How To Change The Visudo Default Editor

In this quick tutorial, we will quickly walk you through how to change and configure your system's default visudo editor.
Captain Salem 1 min read
How To Change The Visudo Default Editor

In Unix-based systems, visudo is a command-line utility that provides a secure way to edit the /etc/sudoers file.

Using visudo helps to ensure proper syntax and prevents simultaneous edits, reducing the risk of errors and unauthorized changes in the sudo configuration.

By default, the visudo command will use the vi editor. However, you will encounter instances where you must change this value to match your preferred editor.

Where is the Default Visudo Editor Defined?

The default editor used by visudo is typically defined by the EDITOR environment variable. This allows you to view and configure the value quickly.

To check your default visudo editor, run the command:

echo $EDITOR

Changing Visudo Default Editor

To change a given editor as default visudo for the current shell session, export EDITOR=editor_name.

export EDITOR=nano

To set the default editor as Vim:

export EDITOR=vim

You should run the command above as root.

Making the Changes Permanent

If you wish the changes to the default editor to persist across reboots, you can add the default editor in the sudoers file as:

Defaults editor=/usr/bin/vim

Using Update Alternatives

If you are on Debian and any Debian-based distribution, you can use the update-alternatives command to change the default editor for visudo as:

sudo update-alternatives --config editor

This should prompt you to choose which editor you want to use. Choose the number of editor and press ENTER.


In this tutorial, we quickly covered how to change the default editor for visudo.

More from GeekBits

Join us at GeekBits

Join our members and get a currated list of awesome articles each month.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to GeekBits.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.