Switch PHP version on Mac with fish terminal

Switch PHP version on Mac with fish terminal

Posted on:June 7, 2023 at 10:00 AM

If you’re using the Fish shell (/usr/local/bin/fish) on your Mac, you need to source the Fish configuration file to update the environment variables.

Follow these steps:

  1. Run the following command to open the Fish configuration file in a text editor:
nano ~/.config/fish/config.fish

If the config.fish file doesn’t exist, it will be created.

  1. In the config.fish file, add the following line to set the PHP version to 8.2:
set -x PATH /usr/local/opt/[email protected]/bin $PATH

This line adds the PHP 8.2 binary path to the beginning of the PATH variable.

Save the changes and exit the text editor.

  1. Now, to apply the changes and update the environment variables, run the following command in the terminal:
source ~/.config/fish/config.fish

This command sources the Fish configuration file, updating the environment variables.

  1. To verify that the PHP version has been updated to 8.2, run the following command:
php -v

The output should display the PHP version as 8.2.x.