How-To Geek

Change the Default Editor From Nano on Ubuntu Linux

Many of the utilities in Ubuntu Linux use a text editor to allow you to edit configuration options and files. An example of this is using the crontab command, which allows you to edit your cron jobs using the default editor.

It’s really easy to set the default editor using the update-alternatives command. Open up a terminal window and type in the following command:

sudo update-alternatives --config editor

Here’s an example of what you’ll see:

$ sudo update-alternatives –config editor

There are 5 alternatives which provide `editor’.
Selection Alternative
1 /usr/bin/vim
2 /bin/ed
*+ 3 /bin/nano
4 /usr/bin/vim.basic
5 /usr/bin/vim.tiny
Press enter to keep the default[*], or type selection number:

You can select the editor you want by just typing in the number. For example, if I want to change the default editor to vim, I would just hit the number 1.

You can test this out by typing in crontab -e to edit your cron file. You should see the editor that you chose, instead of the default.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 12/5/06

Comments (30)

  1. Warren

    Thanks, I’m only starting to use a Linux OS and was just starting to get to grips with VIM and then having to learn another text editor for Unbuntu would have been an inconvenience.

  2. djancak

    Thanks for this information. I was getting rather fed-up with having to use nano as my default text editor when using crontab.

  3. pd

    This doesn’t seem to work.

    sudo update-alternatives -config editor
    update-alternatives: unknown argument `-config’

  4. andres

    Little tricks make life easier, thanks budy, very helpful.

  5. andres

    this is the correct command

    “update-alternatives –config editor”

    with 2 dashes instead of one

  6. pd

    I found this tip failed. It did nothing after eventually I had to find out the double dash –config thing myself.

    It would also be much more sensible to put tips that rely on strict command line arguments, in a fixed width font to make them easier to read.

    Thumbs down for this tip.

  7. Gustaf

    Does this comment engine change two dashes into one long? Otherwise, _this_ is the correct command:

    “update-alternatives –config editor”

  8. Gustaf

    *Sigh* it certainly did.. Nevermind; sorry for the double posting.

  9. ronald

    maybe write is as ‘update-alternatives – -config editor’ :D

    greetz all

  10. Micah

    When I run update-alternaitives, it only shows ed and nano. Is there anything I can do to to get it to show the other choices?


  11. Gustaf

    Hehe. No, seriously not. “-” is generally a syntax for stdin/stout, can cause trouble..

    A first dumb question then: Have you even installed vim or any other alternatives? I think a full installation of e.g. vim or emacs is not bundled by default.

  12. Micah

    oh yeah – I’ve been using VIM ever since install. In fact, I didn’t know about this and set up VIM as the edior in my .bashrc.


  13. Bauche

    I have installed vim but it does not appears as an alternative. (It appears vim.basic and vim.tiny, but not vim). What con I do?

  14. Gustaf

    vim.basic = vim, so that’s what to choose. Before the installation there was only vim.tiny available.

  15. Ubuntu

    user@Linux:~$ sudo update-alternatives –config editor
    [sudo] password for user:
    update-alternatives: unknown argument `–config’
    user@Linux:~$ sudo “update-alternatives –config editor”
    sudo: update-alternatives –config editor: command not found
    user@Linux:~$ “update-alternatives –config editor”
    bash: update-alternatives –config editor: command not found
    user@Linux:~$ sudo ‘update-alternatives –config editor’
    sudo: update-alternatives –config editor: command not found

    user@Linux:~$ uname -a
    Linux Linux 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12 GMT 2007 i686 GNU/Linux

  16. Gustaf

    Ubuntu: As discussed above – use two hyphens in “- -config”.

  17. blu

    can i add gedit as default ?

  18. tomm174

    alternatives seem like a really poor idea.
    It gives you the command line ease of changing a very unimportant configuration issue, – the name you type to invoke an editor – which each user would be likely to do very infrequently, if ever.
    The cost is making it quite obscure and complicated what is actually happening, and breaking what people out there already understand.
    I suppose Stallman, Cox, Tovalds, Tridgell have all had to waste their time getting their heads around it – unless they just go on using the same install they’ve had for the last five years
    There is a standard environment variable $EDITOR which is supposed to deal with this issue
    I just tried to trace down where emacs directs to on my ubuntu 8. I think it goes through SIX levels of links. I don’t want this kind of (‘scuse me) CRAP on my system. I want to be able to find an executable if there is a problem.
    If it aint broke don’t fix it
    Simpler is bettttttttttteeeeeerrrrrrrrrr – And don’t get me started about upstart
    If I want to use emacs I’ll type ’emacs’ and maybe alias it to ‘e’

  19. gdawg

    Tried to use with only one ‘-‘ hyphen in front of config. Went to ‘man update-alternatives’ to discover that I needed to use two hyphens. Next time I will read the comments before entering commands. Thanks for all the info.

  20. Arla

    The way I discovered that double hyphens were necessary was through running update-alternatives without arguments. That gave me a list of options, where I could see what had to be corrected. Like pd above I recommend that the author use preformatted monospace text for commands and code.

  21. Carlos

    Thanks gdawg. I was having issues too with only ohne hyphen. Read your tips/hint and now it works like a charm! :) People out there:

    sudo update-alternatives –config editor the correct command!

  22. niego


  23. Javaman

    Any way to put into script so that i can run? I wanted run on multiple PC that uses linux.

    Using method give, i need to key in the number on every pc.


  24. romashka

    If this tip doesnt work for you, try not to copy and paste it but type on your own =)
    That helped me.

  25. irado

    why in the hell the simply “cut and paste” doesnot act as expected? if I select/copy with mouse the result is: “sudo update-config editor alternatives” and not “sudo update-alternatives –config editor “.

    I must type the command, instead. Boring, fortunately just once in a life-time

  26. Kent Tong

    Run select-editor to select the editor for each user. It overrides the system default set by update-alternatives!

  27. Joshua

    another attempt to get the illusive double dash to stick in this editor:

    sudo update-alternatives ––config editor

  28. Joshua

    Nevermind, double &ndash didn’t work

  29. Dan

    Look in the home directory of the user for which you would like to change the default editor. Run ls -al. Look for the file named .selected_editor. Open it using your desired editor (e.g., vi .selected_editor) and manually modify the path for the ‘SELECTED_EDITOR’ variable. To set to vi, for example:

    # Generated by /usr/bin/select-editor

    Save the file. This *should* do the same thing as using “select-editor”.

  30. Ydnar

    When a command fails to run and even cleverly give the message
    update-alternatives: unknown argument `-config’

    before blasting the very useful post here, run

    man update-alternatives

    that will clearly demonstrate the two hyphens.

    Everyone should know that their best friend in the *nix world is man.

More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!