Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

When editing files like sudoers, I want to use emacs instead of nano. So I ran this command

sudo update-alternatives --config editor

And I selected emacs. The only issue is I like emacs in no window mode (the -nw flag) and I've aliased emacs as emacs='emacs -nw' so that I can use no window mode in normal use, but I don't know how to get my default editor to be in no window mode.

In other words, I need to get the command sudo visudo and similar commands that open up editors to open the file with emacs -nw. How can I do this? I'm on Ubuntu 12.04.

share|improve this question
up vote 5 down vote accepted

Create a script that starts emacs with -nw flag, e.g. /usr/local/bin/emacs-nw.


emacs -nw "$@"

Install it with update-alternatives --install.

sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/emacs-nw 2

Configure editor to be your new script.

sudo update-alternatives --set editor /usr/local/bin/emacs-nw
share|improve this answer
For those who don't use update-alternatives featured systems, chmod +x /usr/local/bin/emacs-nw and export EDITOR='emacs-nw' in .bashrc do the trick. – smonff Sep 6 '14 at 19:54

Add the following to your ~/.bashrc file (or the config file for your shell if it is not Bash).

export EDITOR="emacs -nw"

This should set (and export) an env variable setting your default editor as Emacs in non-graphical mode.

share|improve this answer
After setting EDITOR how would you open Emacs in graphical mode? – Manolete Mar 2 at 14:59
@Manolete you can use command emacs, this will run Emacs without aliases and such. Of course you can also unalias emacs for a session. – Kyrremann May 4 at 7:52
@Manolete Actually launching emacs with emacs at the command line or clicking on it's icon will still launch the graphical form. The command above in my post just sets the EDITOR enviromental variable to "emacs -nw" it actually does not create an alias. It just tells the shell that your preferred editor is emacs -nw. emacs will still launch the graphical form. – haziz Jul 3 at 11:11

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.