Changing Default visudo Editor in Ubuntu

Ubuntu users commonly employ the visudo command to edit the sudoers file, which controls system permissions for administrative tasks. By default, this command launches the Nano text editor. However, users may prefer alternative editors like Vim or Emacs. Here’s a quick guide on changing the default editor for visudo on Ubuntu.

Step 1: Choosing an Editor Before making any changes, decide which text editor you want to use for editing the sudoers file. Common alternatives include Vim and Emacs.

Step 2: Configuring the Default Editor Open a terminal window and type the following command to set your preferred text editor as the default for visudo:

$ sudo update-alternatives --config editor

There are 4 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
  3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    15        manual mode

Press <enter> to keep the current choice[*], or type selection number: 

Select the number corresponding to the preferred text editor from the list and press Enter.

Step 3: Testing To ensure that the changes have taken effect, run the visudo command in the terminal again. It should now open the sudoers file in your chosen text editor.

Step 4: Adjustments If you decide to switch back to Nano or choose a different editor in the future, simply repeat the above steps and select the desired editor.

Conclusion: By following these steps, you can easily change the default text editor used by the visudo command in Ubuntu. This allows you to work with your preferred editor when making changes to the sudoers file, enhancing your overall user experience.