Change default Crontab editor in bash shell for Raspberry Pi

5.00 avg. rating (96% score) - 2 votes

By default, the editor for the crontab on the Raspberry Pi is the editor specified by the VISUAL or EDITOR environment variables. If neither environment variables is defined, the default editor at /usr/bin/editor is used. On the Raspberry Pi, sometimes even if you have already set the values of VISUAL and EDITOR to your expected editor, for example vi, default editors such as nano may still be used instead.

To fix this, first check the current editor:

$> ls -l /usr/bin/editor

lrwxrwxrwx 1 root root 24 May  7  2015 /usr/bin/editor -> /etc/alternatives/editor

As the current editor is softlinked to /etc/alternatives/editor, we’re going to check this further:

$> ls -lt /etc/alternatives/editor

lrwxrwxrwx 1 root root 9 Jan  4 11:51 /etc/alternatives/editor -> /bin/nano

Clearly, the nano editor is used. Now we will update the editor to Vi using the following command:

$> sudo update-alternatives --config editor

There are three choices for the alternative 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.tiny   10        manual mode

Press ENTER to keep the current choice (marked with *), or type the selection number such as 3 to choose vim.tiny as the default editor.

You can verify that the changes have been made by using:

$> ls -lt /etc/alternatives/editor

The result should be:

lrwxrwxrwx 1 root root 17 Jan  4 11:54 /etc/alternatives/editor -> /usr/bin/vim.tiny

With this, the default editor for the crontab with sudo should be vi.

5.00 avg. rating (96% score) - 2 votes
ToughDev

ToughDev

A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

3 thoughts on “Change default Crontab editor in bash shell for Raspberry Pi

  • July 11, 2017 at 8:08 pm
    Permalink

    This workaround did not work for me, instead I managed to solve the problem by running “/usr/bin/select-editor”:

    pi@iotsrv02:~ $ /usr/bin/select-editor

    /usr/bin/select-editor: 1: /usr/bin/select-editor: gettext: not found
    ‘select-editor’.
    1. /bin/ed
    /usr/bin/select-editor: 1: /usr/bin/select-editor: gettext: not found
    2. /bin/nano <—-
    3. /usr/bin/vim.tiny

    /usr/bin/select-editor: 32: /usr/bin/select-editor: gettext: not found
    1-3 [2]: 3
    pi@iotsrv02:~ $ crontab -e

  • ToughDev
    July 12, 2017 at 12:32 pm
    Permalink

    Thanks for sharing your solution with me :)

  • January 26, 2018 at 5:58 pm
    Permalink

    correct, this solution is not working for me ether, but Efrain’s does.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>