4

When there are bugs in different versions of SFDX CLI and the Plugins: There is a need to switch to another version. But I find uninstalling and re-installing too time consuming. Often people post fixes that refer to a version I am not using, and I wish to give that version a try.

I want to know what is the best way to setup my VSCode and install SalesforceDX and SF CLI etc so that if an issue is introduced into the latest version I am using, I can easily switch to and older version to complete a task and then switch back to the new or different version to continue on?

Options I am looking at, are:

  • Based on the Windows downloaded installation: Once installed I want to easily version switch and how is it best to do this? Is it by uninstalling or using a contextual menu to version switch?
  • Node Installation. Once installed I want to easily version switch and how is it best to do this? Is it by using node commands to version switch or to use the contextual menu to version switch?
  • Happy to receive answers pertaining to MAC or Linux, but my build is currently Windows.
  • Maybe there is a generic solution for all OSes?

NB: I have noted that when I install with Node using "SFDX update" no longer updates I get a message telling me to use a Node command to update "npm update --global sfdx-cli"


Issues I am experiencing but are not what I am asking about they are for CONTEXT ONLY:

  • SF CLI is not authenticating, so I want to adjust the version i am using to enable the auth until the fix comes out.
  • Retrieving metadata, deploying metadata has inconsistent issues various metadata are landing in the wrong folders.
  • Was using version 7.89.2. - I upgraded to 7.90.2 and auth issues went away.

3 Answers 3

6

I suggest using the NPM to install and upgrade for ease of switching between versions.

With this approach, your CLI is not auto upgraded and it is upon you to upgrade by watching the npm registry and reading release notes here.

NPM is a package manager for Node.js. You will need to have Node.js latest version installed along with NPM.

Install Current Stable Version

npm install --global sfdx-cli

This is the version that will be most stable and recommended. It is released every week Thursday! It is also possible sometimes if there is a critical bug there is an immediate release (most unlikely)

Get a version that is ahead of Stable Verison

npm install sfdx-cli@latest-rc

This version is ahead of the stable version and may have potential bugs that went undiscovered. This is also released weekly on Thursday. Salesforce CLI team recommends you have a branch in your continuous integration with this version so that any potential bugs are caught and informed to the team before this is released as stable.

You can switch to the latest stable version from release candidate simply by doing npm install sfdx-cli@latest

Install a specific version

npm install --global sfdx-cli@<version>

You can obtain the version number from here

example npm install --global [email protected]

Uninstall

At any point you want to uninstall the CLI, you can do using below

npm uninstall sfdx-cli --global

The other thing to note is Salesforce CLI is made of a number of core plugins.

If you wish to update one of those, say an example salesforcedx plugin then the command is below

sfdx plugins:install salesforcedx@latest-rc

I highly recommend not to individually try to change versions of these plugins unless you know what you are doing.

Salesforce CLI team published a detailed blog post around the progress around Open sourcing Salesforce CLI.I suggest giving a read

Also, most of the code is Open Source here so you can see the progress and monitor changes.

8
  • Thanks Mohith! I also noted this in the most recent release notes:"If you installed the pre-release version of the salesforcedx plug-in, uninstall it and update the CLI. We’re no longer updating the pre-release and will be removing the tag." Commented Mar 5, 2021 at 2:27
  • @NZDev Please check my enhancements on plugins: install command for plugins that ship along. I highly recommend do not individually try to manage them! Commented Mar 5, 2021 at 2:29
  • 1
    Yes so don't try to change salesforcedx plugin versions using sfdx plugins: install [email protected]! Commented Mar 5, 2021 at 5:07
  • 1
    Yes exactly don't do that because that way when you update via npm it will overwrite so no point Commented Mar 5, 2021 at 5:18
  • 1
    @MohithShrivastava This is an excellent answer - plenty of explanation, examples, and links, and you anticipated several followup questions. These are the best kind of answers on SFSE. Just wanted to acknowledge it. Commented Nov 4, 2021 at 17:37
2

To add to what Mohith Shrivastava replied earlier, you can further improve dependency management via NPM with NVM (Node Version Manager). This will let you run different versions of Node in case you need to test different environments for your projects as may be the case with the CLI. Say you are a consultant that needs to work with different environments for each customer.

Personally, I use zsh as my shell and there is a great plugin called zsh-nvm that will handle updates for NVM.

However, I will point out that module resolution with Node will work differently if you import it into a project via require() or import statements in a JS file. Using a package as a shell would likely use a global install and therefore it will not take advantage of locally installed packages.

I think the best option with a CLI tool especially is to use npx to run a command that could be installed on a project per project basis as a dev dependency or fetched remotely but not installed globally: https://docs.npmjs.com/cli/v7/commands/npx

This blog post does a great job at explaining why npx is the way to go: https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b

0

The npm comments above are valid, but the OP is using the window binary installer, so the answer for that is found in the sf update --help

$ sf update --help
update the sf CLI

USAGE
  $ sf update [CHANNEL] [-a] [-v <value> | -i] [--force]

FLAGS
  -a, --available        Install a specific version.
  -i, --interactive      Interactively select version to install. This is ignored if a channel is provided.
  -v, --version=<value>  Install a specific version.
  --force                Force a re-download of the requested version.

DESCRIPTION
  update the sf CLI

EXAMPLES
  Update to the stable channel:

    $ sf update stable

  Update to a specific version:

    $ sf update --version 1.0.0

  Interactively select version:

    $ sf update --interactive

  See available versions:

    $ sf update --available

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .