Introduction
Salesforce CLI has become essential for modern Salesforce development, enabling source-driven workflows and CI/CD pipelines. While there are multiple ways to install the CLI, this guide focuses on using Node Package Manager (NPM) – a method that aligns with modern software development practices, offering simplicity, flexibility, and robustness.
Note: The older
sfdx-clipackage is deprecated. This guide covers the current@salesforce/clipackage. Bothsfandsfdxcommands work identically in the new CLI – your existing scripts remain compatible.
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/[email protected] --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
- Ensure you have Node.js and NPM installed (versions 20.9 or higher recommended). Visit Node.js for download and installation instructions.
- Familiarity with basic command-line operations and NPM is assumed.
You can check your Node.js and NPM versions by running the commands
node --versionandnpm --versionrespectively.
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.x.x. Bothsfandsfdxcommands work. - Keep the CLI updated: Salesforce releases weekly updates with new features and security patches:
npm update @salesforce/cli --global
Getting errors? Permission denied, command not found, or PowerShell policy errors are common. See How to Fix Salesforce CLI NPM Installation Errors for solutions.
Notes and Best Practices
- Use nvm (Recommended): Installing Node.js via nvm (Node Version Manager) 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/[email protected] --save-devnpx sfinstead of the globalsf. - sf vs sfdx Commands: Both commands work identically. The
sfdxcommand is an alias for backward compatibility. Salesforce recommends usingsffor new projects. - Integration with CI/CD: Salesforce CLI integrates with Jenkins, GitHub Actions, GitLab CI, and other automation tools. See the Salesforce CLI Setup Guide for details.
Conclusion
Using NPM for Salesforce CLI installation provides version control, CI/CD compatibility, and cross-platform consistency that standalone installers lack. Remember to use @salesforce/cli (not the deprecated sfdx-cli), and consider using nvm to avoid permission headaches.
If you run into installation problems, check out How to Fix Salesforce CLI NPM Installation Errors for step-by-step solutions to common issues.