Change Default crontab editor CentOS

 
I was working on some sysadmin tasks on a freshly installed server, and I found out the crontab editor was not what I expected it to be. I really like vi (or vim) for command line editing, so I wanted ‘crontab -e’ to use vim instead of something else. To make that happen, I put this into my roots .bashrc file (location: ~/.bashrc):


export EDITOR=vim
export VISUAL=vim

or from the command line


export EDITOR=/usr/bin/vim
export VISUAL=vim

If using CentOS7 – System Default Editor
During login, a number of scripts are run to setup the environment. In CentOS, a file for each subject is used. These are stored in a system profile directory, /etc/profile.d/. There are two environment variables that control which editor to use.

cat < >/etc/profile.d/vim.sh
export VISUAL="vim"
export EDITOR="vim"
EOF

Per User Default
If a user wishes to set the default editor for themselves, it can be, instead, be done in the user’s bash profile.

cat < >~/.bash_profile
export VISUAL="nano"
export EDITOR="nano"
EOF

Activating Changes
Some of the changes made won’t take effect on the current session. Log out and back in to activate the changes.

Testing
Scheduling jobs is one multi-layer process that uses a text editor. Editing the current user’s scheduled jobs is one way to test which editor is the default.
crontab -e
If it is still nano, use ctrl+x to exit. If you are using vim, congratulations! Use “:q” to exit.

I keep forgetting this, so I decided to blog it. Don’t forget to reload the bashrc by doing this:

source ~/.bashrc

If you are in the same situation and want to change the editor to nano, here is the simple command that will change your default OS editor.

export VISUAL=’pico -w’

Now when you run:

crontab -e

Nano will open up. Don’t forget to logout and log back in to see the changes.

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.