Change default Crontab editor in bash shell for Raspberry Pi
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.
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
Thanks for sharing your solution with me
correct, this solution is not working for me ether, but Efrain’s does.