How to change the default crontab editor

I want to have crontab use the editor of your choice instead of the other way around? This tutorial shows you how. These instructions work with Linux, macOS, and other Unix-like operating systems.

The tricky subject of text editors

A text editor does a rather mundane task. Yet the depth of feeling people associate with their personal preference editor has led to that Flame Wars that have been burning since 1985. We neither stir up this fire nor do we put one editor above another. We’ll show you how to change the default editor for crontab to something else, should you choose to do so.

the crontab -e Command opens an editor so you can edit your cron table. Your cron table contains the list of all the scheduled jobs that you ran at specific times. We won’t go into the details of cron jobs in this article. We’ll just look at the editor associated with that crontab -e Command.

How to Schedule Tasks on Linux: An Introduction to Crontab Files

The very first time you do the crontab Command with the -e (edit) in a bash terminal you will be prompted to select the editor you want to use. Type crontab , a space, -e and press Enter.

crontab -e

The editor you choose will then be used to open your cron table. In this example, nano was selected by pressing button 1.

Cron table in the nano editor

The editor you choose from the menu is used every time you open the crontab -e Command. If you change your mind later, how do you choose a different editor when you only get the menu the first time? That’s easy. The command to use is select-editor.


Select editor command

So far, so easy. But what if you want to use an editor that isn’t on that menu? Or what if you have an operating system that supports the select-editor Command? We can also deal with these scenarios.

What about distributions that don’t provide a select editor?

We can set the default editor for crontab by adding a line to our .bash_profile file. Enter this command:

gedit ~/.bash_profile

When the editor appears, add this entry to the file:

export VISUAL="gedit"

Of course, you’d replace ‘gedit’ with the command that launches the editor you want to use. Save this file and close the editor. To see if these changes take effect, either sign out and sign back in, or enter this command:

. ~/.bash_profile

Notice that the line begins with a period or a period. the source command is an alias for the period command and performs the same action. But not all distributions offer this source Command. The period command should always be present. After you have made this reservation, source Command was present on all distributions in which this article was against Ubuntu, Debian, Manjaro, Arch, Fedora, CentOS and OpenIndiana.

Whether you enter a period or the word source, the command causes the settings to be read from your .bash_profile and transferred to your current session. If you enter now:

crontab -e

The editor you specified will be used to open your cron table.

Cron table in gedit

Your .bash_profile file may not be empty

Your .bash_profile file might not be empty when you edit it. Just scroll down and add that export VISUAL="gedit" Line at the end of the file. This is the default .bash_profile in Manjaro Linux, with the new line added:

And finally, OpenIndiana

With OpenIndiana you have to use the export VISUAL="gedit" Line in your .bashrc file, not in your .bash_profile. The command you need to enter is:

pluma ~/.bashrc

.bashrc in pluma

Add the line and save the file, and close and open your terminal window again.

Edition of the crontab -e Command to verify that your changes have taken effect:

crontab -e

Cron table in Nano OpenIndiana

And now your cron table will be loaded into nano.

Now you can specify the editor of your choice for many types of Linux, whether it’s Debian, RedHat, Arch, or something closer to a plain vanilla Unix.

Linux commands
Filestar · pv · cat · tac · chmod · grep · difference · sed · With · man · pushed · popd · fsck · Test disk · seq · fd · pandoc · CD · $ PATH · awk · join · jq · wrinkles · unique · Journalctl · tail · stat · ls · fstab · echo · fewer · chgrp · chown · rev · look · Strings · Type · rename · Postal code · unzip · assemble · ummount · To install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · weather · Nano · mkdir · from · ln · Patch · Convert · rclon · Scraps · srm
Processesalias · screen · above · kind · renice · progress · strace · system · tmux · chsh · story · at · Batch · for free · which · dmesg · chfn · User mod · ps · chroot · xargs · tty · pinkie finger · lsof · vmstat · Time out · Wall · Yes sir · kill · sleep · sudo · it is · Time · groupadd · User mod · groups · lshw · switch off · start anew · Stop · switch off · passwd · lscpu · crontab · date · bg · fg
Networkingnetstat · Ring · Trace route · ip · ss · who is · fail2ban · bmon · she · finger · nmap · ftp · curl · wget · who · who am I · w · iptables · ssh-keygen · ufw

Best Linux Laptops for Developers and Enthusiasts

Related Posts