This post was originally published on go2linux.org on January 5, 2009. The domain is no longer mine, but I am the original author. I am republishing it here on garron.me with corrections and improvements.
Introduction
Many system commands open a text editor when needed — visudo, crontab -e, git commit, systemctl edit, apt changelog. On Debian and Ubuntu, you can control which editor they use in several ways.
Method 1: update-alternatives (system-wide)
update-alternatives manages the system-wide editor alternative, which affects all users:
sudo update-alternatives --config editor
You will see a list of installed editors:
There are 4 choices for the alternative editor.
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/vim.basic 30 auto mode
1 /bin/nano -2 manual mode
2 /usr/bin/vim.basic 30 manual mode
3 /usr/bin/vim.tiny 15 manual mode
Press <enter> to keep the current choice[*], or type selection number:
Type the number for your preferred editor and press Enter. The change applies immediately to all users.
Method 2: select-editor (per user, Ubuntu/Debian)
On Ubuntu and Debian, each user can set their own preferred editor with select-editor:
select-editor
This writes the choice to ~/.selected_editor. Commands like crontab -e respect this file before falling back to the system default.
Method 3: EDITOR and VISUAL environment variables
Many programs — especially terminal tools and Git — respect the EDITOR and VISUAL environment variables rather than the system alternative.
Set them for your current session:
export EDITOR=nano
export VISUAL=nano
To make it permanent, add those lines to your ~/.bashrc (or ~/.zshrc for zsh):
echo 'export EDITOR=nano' >> ~/.bashrc
echo 'export VISUAL=nano' >> ~/.bashrc
source ~/.bashrc
Which method to use
| Scope | Method |
|---|---|
| All users, system commands (visudo, crontab) | sudo update-alternatives --config editor |
| Current user, crontab -e on Ubuntu/Debian | select-editor |
| Current user, Git, CLI tools | EDITOR / VISUAL in ~/.bashrc |
For a consistent experience, set both update-alternatives (or select-editor) and the environment variables — they cover different programs.
Common editors and their paths
| Editor | Path |
|---|---|
| nano | /bin/nano |
| vim | /usr/bin/vim.basic or /usr/bin/vim |
| neovim | /usr/bin/nvim |
| emacs | /usr/bin/emacs |
| micro | /usr/bin/micro |