When running system administration tools such as crontab -e, visudo, git commit, or systemctl edit in Ubuntu, the operating system launches a command-line text editor to handle the file revision. By default, Ubuntu assigns GNU nano as the system-wide editor. While nano provides a gentle learning curve for beginners, experienced developers and sysadmins often prefer Vim, Neovim, or Micro.
Ubuntu manages default binary selections through the update-alternatives system, which maintains symbolic links in /etc/alternatives/ to ensure commands reference your favoured software.
Changing the System-Wide Default Editor
To configure your preferred editor across all administrative commands:
- Open your terminal in Ubuntu.
- Execute the following configuration command:
sudo update-alternatives --config editor - The terminal will print a numbered menu of all text editors currently installed on your system:
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: - Type the number corresponding to your preferred editor (for example,
3for standard Vim) and press Enter.
Testing Your New Default Editor
Verify that your selection took effect by invoking the generic editor wrapper:
editor /tmp/testfile.txt
The chosen program should open immediately. Close or quit the editor when finished.
Setting the Editor for a Specific User via Environment Variables
If you do not possess root or sudo privileges, or if multiple users share the same server with differing editor preferences, configure your user profile environment variables:
- Open your shell configuration file in your home directory:
nano ~/.bashrc - Scroll to the end of the file and export the
SELECTED_EDITOR,EDITOR, andVISUALvariables:export EDITOR="/usr/bin/vim" export VISUAL="/usr/bin/vim" - Save the file and apply the changes immediately:
source ~/.bashrc
Commands that query POSIX environment standards will now respect your personal selection without affecting other system accounts.