Specify an Editor for Crontab on Linux

The default editor for crontab on Linux is the vi editor. However, this can be changed by setting the VISUAL or EDITOR environment variable to the desired editor before running the crontab command. For example, to use nano as the editor for crontab, the command would be ?

export VISUAL=nano; crontab -e

or

export EDITOR=nano; crontab -e

This will open the crontab file in nano for editing.

Methods to Change Crontab Editor

Temporary Change

To temporarily change the editor for a single crontab session, set the environment variable inline ?

VISUAL=nano crontab -e

Permanent Change

To permanently change the default editor, add one of these lines to your ~/.bashrc or ~/.profile file ?

export VISUAL=nano
export EDITOR=nano

After adding the line, reload your shell configuration ?

source ~/.bashrc

Popular Linux Text Editors

Several text editors are commonly used with crontab ?

Editor Command Description
vi/vim vi, vim Powerful modal editor, default on many systems
nano nano Simple, user-friendly with on-screen help
emacs emacs Highly customizable with extensive features
joe joe WordStar-like interface, easy to learn

Using select-editor Command

Some Linux distributions provide the select-editor command for interactive editor selection. On Ubuntu and Debian systems, you can use ?

select-editor

This presents a menu of available editors. Alternatively, use the update-alternatives command ?

sudo update-alternatives --config editor

The output shows numbered options like ?

Selection    Path                Priority   Status
* 0          /bin/nano            40        auto mode
  1          /bin/nano            40        manual mode
  2          /usr/bin/vim.basic   30        manual mode
  3          /usr/bin/vim.tiny    10        manual mode

Press <enter> to keep the current choice[*], or type selection number:

Editor Priority

Linux follows this priority order when determining which editor to use ?

  1. VISUAL environment variable

  2. EDITOR environment variable

  3. System default (usually vi or nano)

The VISUAL variable takes precedence over EDITOR because it was originally intended for full-screen editors.

Conclusion

Changing the crontab editor in Linux is straightforward using environment variables or system configuration tools. The choice between VISUAL and EDITOR variables, along with tools like select-editor, provides flexibility in customizing your editing environment for cron job management.

Updated on: 2026-03-17T09:01:38+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements