How to Update Shell Programs on macOS

bashcommand lineterminal

How do I update shell programs like crontab for example?
On my Mac I've got version from 29th of December 1993, but on a server linux machine that I am using version of crontab is much better in terms of usability since it's from 19th of April 2010.

I am running MacOS Mojave and my bash version is :
GNU bash, version 5.0.2(1)-release (x86_64-apple-darwin18.2.0)

crontab on my Mac:
Mac
crontab on my Linux:
Linux

Best Answer

Where is the executable?

command -v cron

The result shows /usr/sbin/cron. System Integrity Protection (SIP) protects the contents of /usr; thus we cannot affect a change anyway as long as SIP is enabled. You installed BASH via Homebrew, I take it. Searching Homebrew for cron-related formulae or casks reveals no candidates (brew search cron), perhaps for reasons given by @nohillside. Perhaps cron was a bad example and a better example might be vim. As you have discovered, one can utilize a package manager like Homebrew or Macports to install more recent software. For each installed package, Homebrew, at least, installs a symbolic link to wherever the executable was installed (/usr/local/Cellar/[...]); thus, we could utilize a shell alias or modify the PATH environment variable to utilize better versions of common software. I use the shell alias approach.

For example, my shell is zsh, and I have installed MacVim. If the symbolic link for MacVim's version of vim exists (-h), then define a new alias. Now, every time I execute vim, I am not executing the vim located in /usr/bin; rather, I am executing the vim located in /usr/local/bin. The below test and definition works the same for bash.

[ -h '/usr/local/bin/vim'  ] && alias vim='/usr/local/bin/vim'
[ -h '/usr/local/bin/view' ] && alias view='/usr/local/bin/view'

And then use the package manager to update the software periodically.

if brew update 2>/dev/null; then
    brew upgrade
    brew cleanup
    rm -rf "$(brew --cache)"
fi