crontab logo

When you run crontab -e for the first time, Linux often opens the cron file in vi (or vim), which can be confusing if you don’t know it. The editor crontab uses is controlled by the EDITOR and VISUAL environment variables, so switching it to nano — or any editor you prefer — takes one command. Here’s how to do it for a single session and permanently.

Change the Editor for the Current Session

Set the EDITOR variable, then open crontab. This lasts until you close the terminal:

export EDITOR=nano
crontab -e

Replace nano with vim, micro, or the editor of your choice. This is the quickest fix when you just need to edit crontab once.

Change the Editor Permanently

To make the change stick across reboots, add the variables to your shell profile. For Bash, edit ~/.bashrc (or ~/.bash_profile):

echo 'export EDITOR=nano'  >> ~/.bashrc
echo 'export VISUAL=nano' >> ~/.bashrc
source ~/.bashrc

Now crontab -e will always open in nano for your user. Setting both EDITOR and VISUAL avoids programs that check the VISUAL variable first.

On Debian & Ubuntu: select-editor and update-alternatives

Debian-based systems provide a simpler, system-aware method. Run:

select-editor

This shows a numbered menu of installed editors; pick nano and it’s saved for your user. To change the system-wide default editor, use update-alternatives:

sudo update-alternatives --config editor

Choose the number for your preferred editor. This sets the default for all users who haven’t overridden it.

Verify the Change

echo $EDITOR
# or simply open crontab and confirm it uses the right editor:
crontab -e

FAQ

Q: Why does crontab open in vi? – Because vi (or vim) is the default editor on many Linux systems when the EDITOR variable isn’t set. Set EDITOR=nano to change it.

Q: How do I set nano as the crontab editor permanently? – Add export EDITOR=nano and export VISUAL=nano to your ~/.bashrc, then run source ~/.bashrc. On Ubuntu you can also run select-editor.

Q: What’s the difference between EDITOR and VISUAL? – Some programs check VISUAL first (for full-screen editors) and fall back to EDITOR. Setting both to the same editor avoids surprises.