Sub topic 2
Install the CLI and check the version
This chapter assumes you are comfortable in a terminal, have a Salesforce org you can log in to (a free Developer Edition org works), and know what orgs, metadata, and Apex are. If you install with npm, you also need Node.js. You will install the Salesforce CLI, confirm the sf command works, and learn what to check when it doesn't.
Choose an install method
The Salesforce CLI ships as the sf command. There are two common ways to get it:
| Method | Best for | Notes |
|---|---|---|
| Platform installer (macOS `.pkg`, Windows `.exe`) | Most individual developers | Bundles what the CLI needs and puts `sf` on your PATH. |
| npm package `@salesforce/cli` | Machines that already have Node.js, CI servers | You manage the Node.js version yourself. |
This chapter uses npm because the same commands work on macOS, Linux, and Windows.
Install with npm
Run the install, then ask the CLI for its version:
npm install --global @salesforce/cli
sf --versionThe --global flag installs the package for your whole user account instead of a single project folder. This puts the sf executable in npm's global bin directory.
The version command prints one line. It contains the package name, the CLI version, your operating system and CPU architecture, and the Node.js version it runs on. If you see that line, the install worked.
Your version numbers will differ from any example you read. The CLI updates often, so don't rely on a specific number.
What happens when you run sf
A diagram helps show where each piece lives.
The loop at the bottom is the most common failure. The install succeeded, but your shell doesn't know where to look for the executable.
Fix common install problems
The command is not found
If the shell reports sf: command not found (or "not recognized" on Windows), find npm's global location:
npm prefix --globalOn macOS and Linux, the executables live in the bin folder inside that prefix. On Windows, they live in the prefix folder itself. Add that folder to your PATH, open a new terminal, and run sf --version again. Existing terminals keep the old PATH, so a fresh window matters.
Permission errors on Linux and macOS
An EACCES error means npm tried to write to a system directory your user can't change. Don't fix this with sudo npm install. That creates root-owned files that cause more permission errors later. Instead, configure npm to use a global directory in your home folder, or install Node.js with a version manager such as nvm, which keeps everything in your home directory.
An unsupported Node.js version
The CLI requires a current long-term-support (LTS) release of Node.js. If the install warns about the engine version or the CLI crashes at startup, run node --version and upgrade Node.js to an LTS release.
Mixing installers
If you installed with both the platform installer and npm, two copies of sf can exist. The shell runs whichever appears first on your PATH, which may not be the one you just updated. To see which copy runs, use which sf on macOS and Linux, or where sf on Windows. Keep one install method and remove the other.
Check your setup
Run these three checks before moving on. They take seconds and rule out most problems later:
node --version
which sf
sf --versionOn Windows, use where sf in place of which sf.
The version command doesn't contact Salesforce and doesn't need a login. You will connect the CLI to an org in a later chapter.
Exercise
You installed the CLI with npm and ran sf --version. The shell replies "command not found". Which command shows you the folder to add to your PATH, and why shouldn't you retry the install with sudo?
Show answer
Run npm prefix --global to find npm's global location. On macOS and Linux the executables are in its bin folder, and on Windows they are in the prefix folder itself. Add that folder to PATH and open a new terminal. The install already succeeded, so reinstalling won't help. Using sudo also creates root-owned files that cause permission errors on later installs and updates.
Exercise
sf --version works, but after you update the CLI it still reports the old version. What is the likely cause and how do you confirm it?
Show answer
Two copies of sf are probably installed, for example one from the platform installer and one from npm. The shell runs the first one on PATH. Run which sf (macOS and Linux) or where sf (Windows) to list which copy runs, then remove one install method.