What Editor Does Visudo Use by Default in Ubuntu
When managing sudo privileges on Ubuntu, the visudo command ensures safe editing of the sudoers file by checking for syntax errors before saving. By default, this tool typically opens the nano text editor, providing a user-friendly interface for system administrators. However, this behavior depends on system configuration and environment variables, allowing users to switch to editors like vi or vim if preferred. This article explains the default setting and how to modify it.
Default Editor Configuration
On standard installations of Ubuntu, visudo uses
nano as the default text editor. This choice is made
because nano is generally more beginner-friendly than vi or vim,
displaying on-screen commands for saving and exiting without requiring
memorized keystrokes. When you run the visudo command without any
additional flags, it will launch nano to allow you to edit the
/etc/sudoers file safely.
How to Verify the Current Editor
You can confirm which editor is currently set to open with visudo by checking the system alternatives configuration. Run the following command in your terminal:
sudo update-alternatives --config editorThis command lists all available editors configured on your system. The editor marked with an asterisk (*) is the current default. If nano is selected, visudo will launch nano when executed.
How to Change the Default Editor
If you prefer using vi, vim, or another text editor, you can change the system default permanently. Execute the following command in your terminal:
sudo update-alternatives --config editorYou will see a list of installed editors with corresponding selection
numbers. Enter the number associated with your preferred editor and
press Enter. Future instances of visudo will now open using your
selected editor. Alternatively, you can set the EDITOR
environment variable for a single session by running
export EDITOR=vim before typing visudo.