Back to lessons

Apple Terminal

See Exactly Which Command macOS Will Run

Multiple versions of the same command are installed and the shell may be choosing the wrong one.

Command

command -v node && node -v

What changed

Nothing changes. The command prints the resolved executable path and version.

Danger

safe

When to use it

Use when a CLI behaves like an old or unexpected version.

When not to use it

Do not rely on which alone for shell functions or aliases. command -v is more shell-aware.

Undo or recovery

No undo needed because this command is read-only.

Expected output

A filesystem path such as /opt/homebrew/bin/node followed by a version string.

demo script

Disposable terminal steps

  1. printf '%s\n' '/opt/homebrew/bin/node'
  2. printf '%s\n' '/opt/homebrew/bin/node' 'v22.11.0'

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ printf '%s\n' '/opt/homebrew/bin/node'
/opt/homebrew/bin/node
::exit-code::0
$ printf '%s\n' '/opt/homebrew/bin/node' 'v22.11.0'
/opt/homebrew/bin/node
v22.11.0
::exit-code::0

YouTube Short

Which Node is running?

When a command acts strange, ask the shell what it will run. command -v gives the resolved path.

LinkedIn hook

Before blaming npm, Python, or Git, check the binary your shell actually found.

Question: What command has bitten you most often because the wrong version was first in PATH?

experiments

A/B tests to run

Metric: click_through_rate

A: Use Node as the concrete example.

B: Keep the lesson generic across all CLIs.