- Check if grep is installed
grep --version
If it returns below
grep (BSD grep, GNU compatible) 2.6.0-FreeBSD
- Then install it using brew
brew install grep
- Add below shell script to
~/.zshrc
# determine versions of PHP installed with HomeBrew
installedPhpVersions=($(brew ls --versions | ggrep -E 'php(@.*)?\s' | ggrep -oP '(?<=\s)\d\.\d' | uniq | sort))
# create alias for every version of PHP installed with HomeBrew
for phpVersion in ${installedPhpVersions[*]}; do
value="{"
for otherPhpVersion in ${installedPhpVersions[*]}; do
if [ "${otherPhpVersion}" = "${phpVersion}" ]; then
continue;
fi
value="${value} brew unlink php@${otherPhpVersion};"
done
value="${value} brew link php@${phpVersion} --force --overwrite; } &> /dev/null && php -v"
alias "${phpVersion}"="${value}"
done
- Re-compile
~/.zshrc
file
source ~/.zshrc
- Run commands like this to switch to specific version
e.g. 8.2
should return as below
PHP 8.2.1 (cli) (built: Jan 12 2023 03:48:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies