?前提条件:如果mac电脑还没安装多个PHP版本,可以先看这篇安装一下
#先解除现在默认的php版本
brew unlink php@7.4
#再设置的想要设置的php版本
brew link php@8.1
1、打开mac电脑的终端窗口
2、确认电脑中已经有安装多个版本的php:ls /usr/local/opt/
3、确认当前php版本,输入命令:php -v
可以看到php命令默认的PHP版本
PHP 7.4.29 (cli) (built: Apr 14 2022 11:49:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
????with Zend OPcache v7.4.29, Copyright (c), by Zend Technologies
4、删除链接:brew unlink php@7.4
Unlinking /usr/local/Cellar/php@7.4/7.4.29... 25 symlinks removed.
5、确认已删除:php -v
-bash: /usr/local/bin/php: No such file or directory
6、换上php8 :brew link php@8.1
7、查看默认php命令是否已经切换成功:php -v
PHP 8.1.5 (cli) (built: Apr 16 2022 00:24:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
? ? with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies