Sub topic 5
Checking your Salesforce CLI installation
This chapter assumes you have a terminal, a Salesforce org where you are a system administrator, and basic familiarity with Setup. You will confirm that the Salesforce CLI (sf) is installed and that it can run the commands later chapters rely on. You will not log in to any org yet.
Why check first
Every later step calls sf. A missing or outdated install causes confusing errors, such as "command not found" or "unknown command". These errors look like Salesforce problems but are local setup problems. Checking now takes under a minute.
The current CLI uses the sf command, with commands in the form sf <topic> <action>. An older CLI used sfdx with colon-separated commands such as sfdx force:org:create. This tutorial uses sf only.
Confirm the version
Run:
sf --versionA healthy install prints the CLI version, your operating system, and the Node.js version. The output looks like this:
@salesforce/cli/2.x.x linux-x64 node-v20.x.xThe exact numbers differ on your machine. If you see a version, the CLI is installed and on your PATH.
Inspect the install in more detail
Two commands give more information:
sf version --verbose
sf plugins --coreThe first lists the plugins bundled with the CLI. The second shows the core plugins. The scratch org commands in this tutorial come from the org and project plugins, which ship with the CLI by default. You do not need to install anything extra.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `sf: command not found` | CLI not installed, or its folder is not on `PATH` | Install the CLI, then open a new terminal window |
| `sf` works in one terminal but not another | `PATH` was changed after that terminal opened | Close and reopen the terminal |
| `Warning: sf update available` | A newer version exists | Update the CLI (see below) |
| Only `sfdx` works | You have the legacy CLI only | Install the current `@salesforce/cli` |
Keep the CLI current
Salesforce releases CLI updates often, and scratch org features depend on recent versions. Update with the method that matches how you installed it.
If you installed with the installer for your operating system, run:
sf updateIf you installed with npm, run:
npm install --global @salesforce/cliMixing the two methods can leave two copies of sf on your machine. If sf --version does not change after an update, check which copy runs:
which sfOn Windows, use where sf instead.
How the checks fit together
What comes next
With a working sf, you can authorize your Dev Hub from the command line once Dev Hub is enabled. Later chapters cover that step.
Exercise
You run sf --version and get "command not found" right after installing the CLI with an installer. Name two things to try, in order.
Show answer
First, close the terminal and open a new one, because the installer changes PATH and existing terminals do not pick up the change. If it still fails, check that the CLI's install folder is on PATH (use which sf or where sf to see whether the shell can find it), and reinstall if it is missing.
Exercise
After running npm install --global @salesforce/cli, sf --version still shows an old version. What is the most likely cause, and how do you check it?
Show answer
A second copy of sf, such as one from an earlier installer, is earlier on PATH and runs instead of the new one. Run which sf (or where sf on Windows) to see which copy runs, then remove the old copy or update it with the method you used to install it.