On Linux and Unix-based systems, the crontab command helps you schedule tasks so they can automatically run in the background at a specified time or interval.

When you start crontab for the first time, you’ll see a prompt asking you to choose the default text editor for editing crontab files. But what if you want to change the editor later on?

crontab Recommends nano

Most Linux systems will recommend you to use nano as the default crontab file editor because of its ease of use. But of course, that is subjective, so you should choose an editor that you are most comfortable with.

If you previously set an editor as your default but want to use a different one this time around, here’s how you can do it.

1. Using the select-editor Command

choosing the default editor on linux

The select-editor command gives you the option to choose your default or preferred text editor on Linux systems.

Run the select-editor command and you’ll be presented with a list of text editors that you can choose from. Some of the common choices include Vim, Emacs, nano, and gedit.

To select the editor of your choice, type the corresponding number and press Enter.

The next time you run the crontab -e command, your crontab file will open in the editor that you’ve set.

2. Using Environment Variables

If you do not have select-editor installed on your system, you can use the EDITOR environment variable on Linux instead. The EDITOR variable specifies the path to the text editor that the system should call when crontab runs.

To set the EDITOR variable, use the following command:

        export EDITOR=/path/to/editor
    

For example, to set nano as the default text editor, you can run:

        export EDITOR=/usr/bin/nano
    

You can also set the EDITOR variable in your shell configuration files, such as ~/.bashrc or ~/.bash_profile, to make the change permanent. For example, to make nano your default editor, add the following line to your ~/.bashrc or ~/.zshrc file, depending on the shell that you are using:

        export EDITOR=/usr/bin/nano
    

To apply the changes without logging out, run the following command:

        source ~/.bashrc
    

After setting the EDITOR variable, you can use the crontab command as usual to create or edit crontab files. For example, to edit your current user's crontab file, you can run:

        crontab -e
    

Use crontab to Automate Tasks on Linux

crontab is a powerful automation tool on Unix-based systems, and you’ll find it handy for scheduling tasks on your Linux system. It's recommended you use the text editor that you are most comfortable with for editing cron jobs.

You can use crontab to schedule a wide variety of repetitive tasks on Linux. For example, taking back-ups, downloading files, or simply cleaning your PC.