38

ERROR

C:\>cordova

'cordova' is not recognized as an internal or external command,
operable program or batch file.

My Environment Path

C:\>path
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;C:\Program Files\nodejs\;C:\Program Files (x86)\Git\cmd
;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\Windows Kits\8.
1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\B
inn\;C:\Program Files\Microsoft\Web Platform Installer\;**C:\Program Files\ANT\apa
che-ant-1.9.3\bin;C:\Program Files\Java\jdk1.7.0_51\bin;C:\Development\sdk\tools
;C:\Development\sdk\platform-tools;C:\Development\cordova-3.3.0\cordova-android\
bin;**

NB: I have read every available tutorial, followed at least 10 of them, read all the similar questions about 'phonegap' not recognized,, .etc. I have my 'Enabled' registry set to 1 as some solutions have suggested, re-installed 'phonegap' & 'cordova' through NPM install -g phonegap, and same for 'cordova', and I still can't get them to run.

I copied an old phonegap application that I made on another PC, and I can run it through just fine. Hope this would clear anything up.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Roshdy
  • 1,703
  • 3
  • 25
  • 34
  • Which version of cordova or phonegap have you installed, how have you installed it? – QuickFix Feb 20 '14 at 13:02
  • cordova 3.3.0 as shown in the path variable, and about phonegap, I'm so lost that I don't know if I'm even using it!!! Cuz as fas as i understand it's only cordova now since cordova 2.0 – Roshdy Feb 22 '14 at 10:11
  • if you use cordova, you don't use phonegap. If you use phonegap you also use cordova. Phonegap is the adobe flavour of the apache cordova (formerly named phonegap) project. The main (only?) interest of phonegap is the possibility to use phonegap build to build app without having to install anything. – QuickFix Feb 22 '14 at 19:06
  • As of 3.3.0, it is advised to stay away from the `phonegap` flavour. Official documentations have been updated with the use of `cordova` command. PhoneGap installations should be done via `npm install -g cordova`. – James Wong Feb 24 '14 at 02:41
  • @JamesWong have you seen an anouncement about this? I've seen that 3.3 docs didn't mantion phonegap cli in the samples anymore but now it reapeared in edge docs (cli part but not platform guide) and I couldn't find any info about it. Quite confusing... And I don't think we can use a config.xml created with cordova in phonegap build. – QuickFix Feb 24 '14 at 08:37
  • 1
    @QuickFix I haven't seen any annoucement, it just came as a surprise to my whole team when the next day all the `phonegap` command was replaced by `cordova` in the documentation. You are right that in the Edge version it is showing `phonegap`. With our experience, we have learnt to believe 60% of the doc and doubt the remaining 40%. Sorry can't help you for PhoneGap Build, our apps exceed their size limitation -_-' we are forced to build locally. – James Wong Feb 24 '14 at 09:00

13 Answers13

57

You do not need to add any cordova folder to the path.

cordova command is a nodejs npm script, what you need is to have the npm folder in your path :

%appdata%\npm\

or if it does not work, use instead

c:\users\YourUserName\AppData\Roaming\npm\

(replace YourUserName with the name of your user profile)

What's strange is that I don't remember I had to change it manually, I think it should be added automatically when installing node and npm.

QuickFix
  • 11,661
  • 2
  • 38
  • 50
  • 6
    I agree with @QuickFix, 1) the `/npm/` folder is missing and 2) If you correctly ran `npm install -g cordova` the `npm` path would have been added automatically. – James Wong Feb 24 '14 at 02:36
  • 1
    it works...Thanks a lot. I wonder why it's not mentioned in the documentation or the corresponding tutorials =S – Roshdy Feb 24 '14 at 11:46
  • 1
    Note: There are two path variables, make sure to enter the path into the system path variable – Black Apr 26 '16 at 12:33
  • @[Black](https://stackoverflow.com/users/4684797/black): For me it worked when added the path in the user path variable not system path variable – Hussain Rahimi Jul 01 '17 at 12:58
  • For me adding "%appdata%\npm\" to the system Path variable did not work but adding "%appdata%\npm" worked. I hope this helps someone. – SubqueryCrunch Jun 29 '21 at 10:51
40
npm install -g cordova

-g is a global install option and it will make the cordova globally available in AppData\Roaming\npm. Restart the prompt if necessary.

Vikram Palakurthi
  • 2,406
  • 1
  • 27
  • 30
13

The Method below is the solution of every such problem related to npm, Be it Phonegap, Cordova, Ionic or else... The concept is that every software installed using npm is saved on this path:

C:\Users\[Your User Name]\AppData\Roaming\npm

So, what we are going to do is just adding the above path to Windows Environment Variable. If you are a begineer, the steps for adding path are as follows:

  1. Go to Control Panel.
  2. Under All Control Panel Items, Go to System.
  3. Click on the Advanced system settings options in the Sidebar.
  4. The System Properties Dialog Box will appear.

You would have done the so far work through searching "Edit Environment Variables" in Search Bar :).

  1. Now, In the System Properties dialog box, there will be Advanced Tab.
  2. In Advanced tab, there will be an option Environment Variables...
  3. Click on it, this will open another Dialog box for Environment Variables.
  4. In System variables, Select Path as shown in image link, and click Edit...

    Path attribute in System Variables

  5. Copy the above path, and add it here as shown in link Copy the Path

  6. Here, you should make sure that the 2 different paths are always seperated by a semicolon ;. Keeping this in mind, add your path to the existing paths.

This will make the application run globally. This is the General Algorithm of steps employed for any type of Path Configuration. If You have any issues left, please feel free to ask.

Kartik Arora
  • 958
  • 1
  • 10
  • 17
11

Try running Command Prompt as an administrator..It worked for me

5

Try restarting the command prompt window. It worked for me.

user2243301
  • 87
  • 2
  • 5
3

Place java path before ant path. change the path according to your paths.

C:\Program Files\Java\jdk1.6.0_20\bin;D:\apache-ant-1.9.3\bin;D:\adt-bundle-windows-x86\sdk\tools;D:\adt-bundle-windows-x86\sdk\platform-tools;C:\Program Files\nodejs\;C:\Program Files\Git\cmd
Pankaj Kharche
  • 1,329
  • 4
  • 15
  • 37
2

Issue is probably with location of node/npm.

npm working? say npm clear cache

Then even if its not working go to Environment Variables. Ensure nodejs is directed to its directory(wherever you installed it)and npm(which is in Users/YourUsername/AppData/roaming) .. its a hidden folder.

The run npm install npm -g OR (if and only if) that gives issues npm install npm@latest

I recommend getting bower too , so say npm install -g bower

Finally npm install -g cordova

There you go!

Leon Africa
  • 509
  • 6
  • 11
1

Open a Command prompt in Run as administrator mode and run the below install command

 npm install -g cordova

Now check if the command is now recognized. (if needed restart the command prompt)

Now in the visual studio code

  1. goto the terminal
  2. Navigate to the cordova folder
  3. Run the usual commands

    cordova platform add android

    cordova run android

Mahendra
  • 447
  • 6
  • 7
1

After installing Cordova is you face the issue then check go to Environment variable (My Computer OR My PC > Right Click > Properties > Advance System Settings > Environemnts Variable button)

add

%appdata%\npm\ or c:\users\YourUserName\AppData\Roaming\npm\

(replace YourUserName with the name of your user profile) to System Variable's PATH

Lakshay Sharma
  • 1,347
  • 12
  • 13
0

I had an issue with the default directories that are used by npm. You can get this list by typing 'npm config list' in the command prompt. In my case, for some reason, the cordova installation was going inside a '=' directory. My Command Prompt pointed me to a 'npm.mrc' file inside 'C:\Users\USERNAME' folder when I typed 'npm config list' from where it is picking up the '=' folder inside 'C:\Users\USERNAME\=' as the default folder for cordova. When I uninstalled node, deleted both the 'npm.mrc' file and the '=' folder and reinstalled node and cordova, this issue disappeared. Hope this helps.

0

I have visual studio installed on my system. Cordova got installed under the following location:

C:\ProgramData\Microsoft\VisualStudio\MDA\c33fb238\taco-toolset-6.3.1

I had to manually add this to PATH.

To know the path where cordova is installed run npm install -g cordova again and the path will be printed on the screen.

Qwerty
  • 1,252
  • 1
  • 11
  • 23
DJ1411
  • 15
  • 4
0

Befor trying any of the answers, just open the node.js command prompt and try again. Press Windows Button => type Node.js => type Cordova inside the node.js command prompt as usual, and thats it. (hopefully)

Dujskan
  • 115
  • 1
  • 10
0

I ran npx cordova build --release android and it worked. Should just work, but here we are.

Enric Ribas
  • 629
  • 6
  • 15