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
.
Since 2008, ToughDev has been publishing technical sharing articles on a wide range of topics from software development to electronics design. Our interests include, but are not limited to, Android/iOS programming, VoIP products, embedded design using Arduino/PIC microcontrollers, reverse-engineering, retro-computing, and many others. We also perform product reviews, both on new and vintage products, and share our findings with the community. In addition, our team also develops customized software/hardware solutions highly adapted to suit your needs. Contact us for more information.