See all UNIX related articles/faq
I am trying to set cronjob on a Unix systems by running the crontab -e command. But, I’m getting the following error:
crontab: no crontab for vivek - using an empty one
crontab: "/usr/bin/vi" exited with status 1

How do I fix this issue on a Linux or Unix-like systems?

You need to set the correct shell environment variable called EDITOR and VISUAL. It appears that either vi is not installed or /usr/bin/vi is a symbolic link to vim editor. To edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux or Unix terminal
Category Processes Management
OS compatibility AIX AlmaLinux Alpine Amazon Linux Arch BSD CentOS Debian Fedora FreeBSD HP-UX Linux macOS Mint NetBSD OpenBSD openSUSE Pop!_OS RHEL Rocky Stream SUSE Ubuntu Unix WSL
Est. reading time 3 minutes

crontab: no crontab for user using an empty one error and solution

When you run:
$ crontab -e
# crontab -e
But, if the shell EDITOR or VISUAL is not set, so you will see an error as follows:

Fig.01: Linux crontab: no crontab for veryv  - using an empty one

Fig.01: Linux crontab: no crontab for veryv – using an empty one

So to fix this error and use vim as a text editor, type the export command (bash/sh/ksh shell specific syntax):
$ export EDITOR=vim
$ export VISUAL=vim

OR if you are using emacs editor, run:
$ export EDITOR=emacs
$ export VISUAL=emacs

Or if you are using nano text editor, enter:
$ export EDITOR=nano
$ export VISUAL=nano

Finally, try to edit or set new cron jobs, enter:
$ crontab -e

Setting the VISUAL and EDITOR variables

I recommend that you edit your shell startup file and append the following line. For example, for bash I edited the .bashrc and added the following two lines:

export EDITOR=vim
export VISUAL=vim

Then used the source command to load changes without rebooting the Linux server:
$ source ~/.bashrc

A note about text editor

The text editor, such as Vim, Emacs, Nano, and others, must be installed on your Linux or Unix-like system. Otherwise, you may encounter additional errors. Use commands like type command, whereis command, and which command to check if the text editor you prefer is installed or not. For example:
$ type vim
$ type vi
$ whereis vim
$ which vim

Also, check your $PATH variable using the echo command or printf command:
$ echo "$PATH"
$ printf "%s\n" "$PATH"

How to fix it no crontab for user - using an empty one
See the following Linux/Unix PATH related tutorials for more info:

Summing up

The $VISUAL is an environment shell variable. It defines the user’s preferred utility (or command) to edit text files. The $EDITOR defines the user’s preferred utility to edit text files on Linux or Unix-like systems. It is an environment variable. It is essential to set these two variables for sysadmin tasks and other commands to function properly in Linux and Unix-like systems. Please check your shell manual pages using the man command/info command or help command for more info. For example:
$ man bash
$ info bash
$ help export
$ man zsh
$ man fish
$ man ksh

See also

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

2 comments… add one
  • Jignesh Boricha Sep 19, 2016 @ 11:47

    Hello There

    Thank you so much for this post. It helped me a lot.

    Actually I was trying setup CRON but I haven’t found the correct way and the missing
    point which I found here only.

    Again, Thank you for sharing this.

    Thank You.

  • laris_fdz Aug 24, 2023 @ 7:04

    thanks, that’s what I needed

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.