In Unix-based systems,
visudo is a command-line utility that provides a secure way to edit the
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:
Changing Visudo Default Editor
To change a given editor as default visudo for the current shell session, export
To set the default editor as 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:
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.