Change default editor of crontab in Ubuntu

Change default editor of crontab in Ubuntu

When you first time open the crontab with command crontab -e it will ask you to set the default editor.
In this tutorial we will see how to set default editor of crontab as well as how to change it to other default editor. I usually work with vi or vim hence in last step I will show two methods to change the default editor for crontab.

Operating System : Ubuntu

This is first time when you open crontab ,follow the given below steps

I am opening the crontab first time and will select nano editor. Later I will change it to vim.

Step 1 : Use the command crontab -e and type 2 for nano and hit enter key, as shown in below given screenshot

crontab
crontab

After selecting option 2 for nano, now you will get the screen like given below.

crontab
crontab

Now by this method the default editor is set to nano editor

Now how to change default editor of crontab

As you have seen with above step I have set default editor with nano editor for crontab.

Now I will change the editor and set it to vim editor. Likewise you can set with other editor.

Step 2 : When you have already set the default editor for crontab ,it will create a file in home directory of user with the name so called .selected_editor ,which is hidden file


root@tuxworld:~# ls -la ~/.selected_editor 
-rw-r--r-- 1 root root 66 Jul  1 21:28 /root/.selected_editor
root@tuxworld:~#

Step 3: We will edit this file but before this I should know the absolute path of my editor , for this I will use which or whereis command. Here I am using which command .

root@tuxworld:~# which vim
/usr/bin/vim
root@tuxworld:~# 

Through which command I got the absolute path of vim i.e /usr/bin/vim

Step 4 : Now edit the .selected_editor with your favorite editor and paste the absolute path of vim in SELECTED_EDITOR then save and exit . I am using vi here

vi ~/.selected_editor 

# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/vim"

to save and exit, press ESC type :wq and hit enter

Now check it, open the crontab with command “crontab -e” you will see it is now vim editor opened crontab file.

crontab
crontab

Another method of changing the default editor

Step 1: By using command “/usr/bin/select-editor” you can also change the default editor.
See the below screenshot and type the number respective of given options for default editor and hit enter.


/usr/bin/select-editor
crontab
crontab

Note: Your desired editor must be installed in system

Recommended Reading :

To know more about where is crontab file in system I will recommend to read this post Edit the crontab without using crontab -e

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.