Why should I install Salesforce CLI with npm?
NPM gives you version control, CI/CD compatibility, and cross-platform consistency that standalone installers lack. If your team already uses Node.js, installing Salesforce CLI through npm keeps your toolchain unified and your builds reproducible.
The
sfdx-clipackage is deprecated and will block installation of the current CLI. If you havesfdx-cliinstalled, you must uninstall it before installing@salesforce/cli. See the migration section below.npm uninstall sfdx-cli --global
Having installation issues? See our guide on How to Fix Salesforce CLI NPM Installation Errors for solutions to common problems like permission errors and command not found.
Why NPM?
NPM, integral to the Node.js ecosystem, brings numerous benefits to Salesforce CLI installation:
- Version Management: Easily switch between CLI versions to meet project-specific requirements. For example,
npm install @salesforce/cli@2.121.7 --globalfor a specific version. - Version Pinning for CI/CD: Lock your team to a specific CLI version for reproducible builds.
- Ecosystem Compatibility: Seamlessly integrates with other Node.js tools, enhancing tooling and automation capabilities in Salesforce development.
- Cross-Platform Consistency: Provides a consistent installation experience across different operating systems, reducing setup overhead.
Prerequisites
- Node.js 24 (Active LTS) or Node.js 22 (Maintenance LTS). Node.js 20 has reached end of life. Visit Node.js for download and installation instructions.
- Familiarity with basic command-line operations and NPM is assumed.
Recommended: Install Node.js via nvm (macOS/Linux) or nvm-windows (Windows) to avoid permission issues and switch Node versions easily.
You can check your Node.js and NPM versions by running the commands node --version and npm --version respectively.
Detailed Installation Steps
- Open your terminal: Use Terminal on macOS/Linux, or PowerShell on Windows.
- Install Salesforce CLI: Run the following command to install the CLI globally:
npm install @salesforce/cli --global - Verify the installation: Check that the CLI is installed correctly:
You should see output likesf --version@salesforce/cli/2.121.7. Runsf doctorto check your environment for common configuration issues:sf doctor - Keep the CLI updated: Salesforce releases weekly updates with new features and security patches:
You can also update using the CLI’s built-in command:npm update @salesforce/cli --globalsf update
Getting errors? Permission denied, command not found, or PowerShell policy errors are common. See How to Fix Salesforce CLI NPM Installation Errors for solutions.
How do I migrate from sfdx-cli to @salesforce/cli?
If you previously installed the old sfdx-cli package, you must fully remove it before installing @salesforce/cli. The new CLI will refuse to install if it detects sfdx-cli on your system.
Check your current installation:
npm list -g sfdx-cliIf this returns a version number, you have the old package installed.
Uninstall the old CLI:
npm uninstall sfdx-cli --globalInstall the current CLI:
npm install @salesforce/cli --globalVerify the new installation:
sf --version sf doctorUpdate your scripts: The
sfdxcommand still works as an alias, but Salesforce recommends updating scripts to usesf. Command syntax has changed — for example,sfdx force:org:listis nowsf org list. See Salesforce’s command reference for the full mapping.
Note: If you see
sfdx: command not foundafter installing@salesforce/cli, that is expected when the alias is not enabled. Usesfinstead.
What are the best practices for managing Salesforce CLI with npm?
- Use nvm (Recommended): Installing Node.js via nvm (macOS/Linux) or nvm-windows (Windows) avoids permission issues and makes switching Node versions simple. This is the approach Salesforce recommends.
- Local Installation for CI/CD: For reproducible builds, install a specific version locally in your project:
Then run commands vianpm install @salesforce/cli@2.121.7 --save-devnpx sfinstead of the globalsf. For full CI/CD pipeline patterns including GitHub Actions and GitLab CI, see our Salesforce CLI DevOps Playbook. - sf vs sfdx Commands: Both commands work after installing
@salesforce/cli. Thesfdxcommand is an alias for backward compatibility. Salesforce recommends usingsffor all new projects and scripts. - Run diagnostics with sf doctor: If something feels off after installation or an update,
sf doctorchecks your Node version, CLI version, plugin health, and environment configuration in one command.
Conclusion
Using NPM for Salesforce CLI installation provides version control, CI/CD compatibility, and cross-platform consistency that standalone installers lack. Install @salesforce/cli (not the deprecated sfdx-cli), use Node.js 24 or 22, and consider using nvm to avoid permission headaches. If you are migrating from the old sfdx-cli package, uninstall it first — the new CLI will not install alongside it.
If you run into installation problems, check out How to Fix Salesforce CLI NPM Installation Errors for step-by-step solutions to common issues.