Skip to content

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

shell
code ./wp-config.php # open file wp-config.php in VSCode
code . # open current directory in VSCode

macOS 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:

bash
xcode-select --install

Homebrew

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.

Learn more about Homebrew

To install Homebrew, run following command:

shell
/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

shell
brew install nvm

Check the shell rc file (run command code ~/.zshrc). Check if these command exists. Add if not exists

shell
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_completion

Then use NVM to install NodeJS. The following command will install the latest version of NodeJS 20.x line.

shell
nvm install 20

You 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

shell
nvm install 16
nvm use 16

When 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

shell
nvm alias default node # set latest version as default
nvm alias default 20 # set version 20 as default

PHP 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

shell
php -v

if PHP is older than 8.2, you can use Homebrew to install newer version

shell
brew install php@8.2

INFO

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

shell
brew install composer

composer is a package manage for PHP (just like npm for NodeJS). It also handling autoloading mechanism in PHP Projects as well.

WP-CLI