How to Change the Default crontab Editor – How-To Geek

To change the default crontab editor on your system, you can follow these steps:

  1. 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 or EDITOR environment variable. You can check it by running the following command in your terminal:
    echo $VISUAL
    echo $EDITOR
  2. 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, and gedit. In this example, we’ll use nano as the new default editor, but you can replace it with your preferred editor’s command.
  3. Set the New Default Editor: To change the default editor for your crontab, you need to set the VISUAL and EDITOR 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
  4. 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.

  5. Save and Apply Changes: Save the changes you made to the profile file (in nano, press Ctrl + O, then press Enter). Exit the editor (in nano, press Ctrl + X).
  6. 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.

Leave a Reply