Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / IoT / Raspberry-Pi

Change Default Crontab Editor in bash shell for Raspberry Pi

5.00/5 (1 vote)
7 May 2023CPOL 7.6K  
This post shows a way to change the 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)