How to Change the Default crontab Editor – How-To Geek
To change the default crontab editor on your system, you can follow these steps:
- Check Current Default Editor: First, you should check the current default editor set for the crontab. The default editor is usually specified by the
VISUAL
orEDITOR
environment variable. You can check it by running the following command in your terminal:echo $VISUAL
echo $EDITOR
- Choose a New Editor: Decide which text editor you want to set as the new default for your crontab. Common editors include
nano
,vim
,emacs
, andgedit
. In this example, we’ll usenano
as the new default editor, but you can replace it with your preferred editor’s command. - Set the New Default Editor: To change the default editor for your crontab, you need to set the
VISUAL
andEDITOR
environment variables to the path of your chosen text editor. You can do this by editing your shell profile file (e.g.,.bashrc
,.bash_profile
,.zshrc
, or.profile
). Open the file in your preferred text editor.For example, using
nano
to edit the.bashrc
file:nano ~/.bashrc
- Add Environment Variable Assignments: Add the following lines at the end of your profile file to set the new default editor:
export VISUAL=/usr/bin/nano
export EDITOR=/usr/bin/nano
Replace
/usr/bin/nano
with the path to your chosen text editor if it’s installed in a different location. - Save and Apply Changes: Save the changes you made to the profile file (in
nano
, pressCtrl + O
, then pressEnter
). Exit the editor (innano
, pressCtrl + X
). - Apply Changes Immediately: To apply the changes immediately without needing to log out and log back in, run the following command:
source ~/.bashrc
If you modified a different profile file, replace
~/.bashrc
with the path to the profile file you edited.
Now, your chosen text editor should be the default editor for your crontab. When you use the crontab -e
command to edit your crontab, it will open the specified editor for you to make changes.
Remember that changing the default editor affects only the current user’s crontab. If you have multiple users on the system, each user can set their preferred default crontab editor following the same steps.