標籤:bash lease this versions prefix 直接 升級 多個 bre
在開發過程中,有時候我們的程式對某個php版本有著極為重要的限制,特別是大型項目。
因此,我們就需要切換多個php版本來滿足我們的需求。
我們使用php-version來達到這個目的。
首先我們先使用brew安裝一個php5.6,為什麼不使用系統原有的php5.6呢?
這個是因為有時候升級系統時,會把內建的php配置給還原,所以我們使用一個新下載的php5.6。
brew install homebrew/php/php56
下載完之後,我們先把php5.6給unlink,不然我們的php7是無法安裝的。會報以下錯誤
Error: Cannot install homebrew/php/php70 because conflicting formulae are installed. php56: because different php versions install the same binaries.Please `brew unlink php56` before continuing.Unlinking removes a formula‘s symlinks from /usr/local. You canlink the formula again after the install finishes. You can --force thisinstall, but the build may fail or cause obscure side-effects in theresulting software
這個時候提示我們需要執行一下
brew unlink php56
接著我們就可以下載php7了
homebrew/php/php70
下載完之後,我們就可以下載php-version了
brew install php-version
這個時候你無法直接使用php-version命令,你需要把下面這句放在~/.zshrc或者~/.bashrc的下面
source $(brew --prefix php-version)/php-version.sh && php-version 5
接著
source ~/.zshrc 或者 source ~/.bashrc
現在的話,你執行php-version就會看到有兩個php版本
? ~ php-version 5.6.31* 7.0.22
帶星號代表著正在使用的是php7.0,只要重啟php,就能成功切換php版本咯
mac使用php-version切換PHP版本