Command Line Tools
This guide will walk you through how to perform first-time setup for command line tools needed for development.
All tools are are available on both macOS and Linux. Though this guide was written primarily for macOS but could also apply to Linux distributions like Ubuntu or WSL on Windows
VSCode Command line Tools
This will let you launch VSCode from command line.
In VSCode, Press F1 and search for command. Then select Shell Command: install 'code' command in PATH. Once installation is completed, you can now open directory or file with VSCode directly from Terminal with code command. For example
code ./wp-config.php # open file wp-config.php in VSCode
code . # open current directory in VSCodemacOS Command line Tools
Brand-new Mac computers didn't ship with developer tools (including Git and compiler library). User can easily install these tools with following command:
xcode-select --installHomebrew
Homebrew is a non-destructive Package Manager designed for macOS (also available on Linux). Homebrew will install packages in its own directory and symclink the command to these installed packages. That when you uninstall the packages, it could revert back the system package automatically.
For example, macOS shipped with PHP 8.0 then you upgrade PHP via Homebrew to PHP 8.4, the 8.4 will be installed inside Homebrew's directory then tell the system to use this package. When you are done and remove PHP 8.4, your system would revert to PHP 8.0 that shipped with macOS.
To install Homebrew, run following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"NVM and NodeJS
NodeJS play crucial role in development workflow as it's being used for assets optimization and compilation.
NVM (Node Version Manager) let you install multiple versions of NodeJS and choose which version to user in per-project fashion.
Install NVM first
brew install nvmCheck the shell rc file (run command code ~/.zshrc). Check if these command exists. Add if not exists
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completionThen use NVM to install NodeJS. The following command will install the latest version of NodeJS 20.x line.
nvm install 20You can choose which version to install as needed. For example if you ran into a project that use NodeJS 16.x then use use command to set version
nvm install 16
nvm use 16When you install multiple version of NodeJS, the lastest version you installed will be use as default version. To chage default version of NodeJS, use the folllowing command
nvm alias default node # set latest version as default
nvm alias default 20 # set version 20 as defaultPHP and Composer
At the time of writing, Sage 11 required PHP 8.2 to work with. Check PHP version in command line if it's already 8.2 or newer
php -vif PHP is older than 8.2, you can use Homebrew to install newer version
brew install php@8.2INFO
Version in command line VS version in LocalWP
If you are using LocalWP as the environment, you will notice that you can also select PHP version inside LocalWP.
Though PHP version select in LocalWP is installed independently. While WordPress would run just fine inside LocalWP, Tools that live outside LocalWP (like composer or wp-cli) still rely on command line version of PHP. So you should keep PHP version in both environment the same.
Once you got the correct PHP version, then install composer using Homebrew
brew install composercomposer is a package manage for PHP (just like npm for NodeJS). It also handling autoloading mechanism in PHP Projects as well.