20

I am trying to learn about Salesforce DX (Developer Experience). For most of the salesforce DX tasks, we require using salesforce command line interface such as authorization, creating scratch org. etc. But I am getting this error message:

Error: 'sfdx' is not recognized as an internal or external command, operable program or batch file

How can I fix it?

2
  • 8
    Sounds like the folder in which you have your executable is not in your PATH environment variable
    – Rob Cowell
    Commented Mar 9, 2017 at 14:06
  • 1
    In my case somehow after I uninstalled SFDX from VSCODE (and uninstalled/resinstalled the SFDX CLI in Win10) my VS Code changed (?) my Terminal window to be using Powershell not a standard command prompt - so THAT is what I was getting "sfdx is not recognized..". After frustrating uninstalls and reboots I realized switching my VS Code Terminal back to a standard command prompt sfdx was working again. Fun. Commented Feb 1, 2022 at 15:28

10 Answers 10

28

1.Verify the "Salesforce CLI" installed successfully or not

Go to → C:\Program Files\Salesforce CLI\bin → Verify sfdx.exe should be availble

2.Add this path to environment variables "Path" Go To → Windows Search → Edit environment variables for your account enter image description here

1
  • 4
    And if you're performing this configuration as an administrator to give permissions to a non-administrator user, adding this environment variable to the System variables PATH (in addition to the User variables PATH) may also be needful.
    – Thom B
    Commented Sep 4, 2020 at 17:53
11

It depends on how you installed SFDX. You have multiple options. The easiest one is, as @Pranay said, to access the official build and just install it using the provided installer: https://developer.salesforce.com/tools/sfdxcli

On the other hand, you can also install SFDX as an npm package, if you're used to work with the Node environment: https://www.npmjs.com/package/sfdx-cli

Furthermore, take into account that if you are using Windows with the Linux subsystem installed, you will not be able to access the SFDX CLI from the Bash if you installed it in windows, or the other way around, so you would have to install it in both places, or just where you'll be working.

Once you've installed the CLI remember to also open a new instance of the console (at least in Windows), otherwise it won't recognize the commands.

9

For my case, all the above solution were not working, because I found that I had multiple sfdx folder due to installation from installer + npm :

  • I had one installed in the following path : C:\Users<>\AppData\Local\sfdx
  • and another one here : C:\Program Files\sfdx

The one installed via npm was at some point in time doing conflict with the other installation. I deleted the folder installed via npm and it works fine now.

5

I faced this issue in VS code all of a sudden (on 22/09/23). I tried searching and experimenting with different solutions proposed here and on other forums but nothing worked. A friend of mine told me that the Salesforce CLI(v7) is deprecated and has been taken over by CLI (v2).

After uninstalling (must-do step) v7 and installing v2, VSCode started working again. No change in configuration or environment variables needed (at least in my case).

Further reading: Salesforce CLI v2 is here

3

You need to install Force.com CLI for SFDX. Use the below link. https://developer.salesforce.com/tools/sfdxcli

2

On mac:

Running the command:

sudo npm install sfdx-cli --global -force

And uninstall and install "Salesforce Extension Pack".

Did the trick for me.

1

I had same problem. When I checked C:\Users\sosawant\AppData\Local I had one folder named sfdx and and in C:\Program Files folder I had another sfdx folder.

I renamed sfdx folder from C:\Users\sosawant\AppData\Local to sfdx.old and tried to ran the command on command line and it worked.

0

After downloading and installing Salesforce CLI, Goto C:\Program Files\sfdx to verify it is installed. Open CMD as an administrator > type sfdx -v > Press Enter key.

It will show the version installed.

Cheers:)

0

I had the same problem with sfdx recently. What i saw in the terminal when printing the Path variable was that echo %Path% would print the Path variable defined in the System variable section instead of the User variable section. Installing sfdx added 'C:\Program Files\sfdx\bin' to the path in the User variable section.

enter image description here

I added the same thing in the Path variable in the System Variable section and it worked !

0

With the change from sfdx (v7) to sf (v2), as mentioned by Mahmood, sfdx deletes itself as there hasn't been an update to it for over 6 weeks.

(https://github.com/forcedotcom/cli/issues/2447)

This worked for me in Windows environment:

CLI commands from command line should be working again.

(Mac install details are here: https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli.htm#sfdx_setup_install_cli_macos)

Also see https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_move_to_sf_v2.htm

You must log in to answer this question.

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