Change default Crontab editor in bash shell for Raspberry Pi

5.00 avg. rating (90% score) - 1 vote

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 (90% score) - 1 vote
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.

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>