Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

"Joe's own editor" does not come naturally to me. How do I change to using nano or vim?

I've tried

export EDITOR=nano

but it doesn't seem to be respected. I'd like visudo to respect this as well.

share|improve this question

migrated from raspberrypi.stackexchange.com Jul 10 '12 at 12:47

This question came from our site for users and developers of hardware and software for Raspberry Pi.

You're way should work but you have to manually export EDITOR each time you start the shell. Try this: echo "export EDITOR=nano" >> ~/.bashrc. – user20601 Jul 10 '12 at 3:05
Thanks Bryan, but it actually wasn't working at all. I'm not sure what the deal was b/c this works in other distros and environments for me. – hidden_premise Jul 10 '12 at 3:25
@BryanDunsmore No, not to ~/.bashrc, to ~/.profile. See Alternative to .bashrc – Gilles Jul 11 '12 at 0:15
up vote 56 down vote accepted

To change the default editor at the system level:

sudo update-alternatives --config editor

and then follow the onscreen prompts.

share|improve this answer
That did the trick! Thanks – hidden_premise Jul 10 '12 at 2:33
If your editor isn't on the list, do this first (for geany) update-alternatives --install /usr/bin/editor editor /usr/bin/geany 10 – PJ Brunet Feb 6 '15 at 5:25
This doesn't work for non-root users – Petr May 28 '15 at 8:02

The way to change the default editor for your account is to set the EDITOR environment variable. If that doesn't work for you, you've done something unusual. Check that you haven't also defined VISUAL, or if you have, give the two variables the same value (see VISUAL vs EDITOR what's the difference?). Add these lines to your ~/.profile (note: not to ~/.bashrc):


Under the Debian policy, all programs are supposed to support EDITOR and VISUAL to set the default editor.

Under Debian and derivatives, you can use the alternatives mechanism to set the system-wide default editor, as mentioned by Steve Robillard: run update-alternatives --config editor as root.

share|improve this answer
+1 works for non-root users - best answer so far – Petr May 28 '15 at 8:02
It is also changing an editor only for you, not for every user. There's a little possibility that someone may not be familiar with vim if you set it system-wide as default editor. – av_lee Jan 4 at 15:06

The solution mentioned above works, but it isn't scriptable. If you want to do this in a scriptable (non-interactive) fashion, you should use --set:

# update-alternatives --set editor /usr/bin/vim.basic

You can get a list of the choices with:

$ update-alternatives --list editor
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.