Why doesn't zsh recognize command from globally installed npm package? - terminal

After installing oh-my-zsh and reinstalling node and npm again, I install npm-check-updates globally and try to call 'ncu' (the npm-check-updates command). However, I get an error: zsh:
command not found: ncu. Does anyone know how to fix this?

I have corrected this problem with the following instructions:
sudo npm install -g npm-check-updates

Make sure the 'ncu' package can be found in the $PATH environment variable. Try this, to find where 'ncu' is supposed to be installed:
which ncu
If it still gives you trouble, try to see if it's in /usr/bin, $HOME/npm/bin, /usr/local/lib or /usr/sbin, and check that your $PATH environment variable contains a way to 'ncu'. Your $PATH environment variable, which can be found in
$HOME/.bashrc (Linux)
$HOME/.bash_profile (MacOS)
should look something like this:
export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/npm/bin

After an install you can run rehash so zsh will analyse what new executables are available on $PATH.
Not sure if that would fix the problem, I know it fixes the missing tab completion entry after install.

FYI I am using a OSX.
The problem was that my export path in my .zshrc was wrong.
This was what it was previously:
export PATH=$HOME/bin:/usr/local/bin:$PATH.
Notice there is nothing pointing at npm or any of the packages I installed globally.
For anyone who has this problem in the future...
Ensure that npm is installed and that you can still run npm commands (if not uninstall then install npm). Then run npm -g list --depth 0 to list all your global packages.
Go into your home folder and press ⌘+Shift+. (shows all hidden files/folders), there should be a .npm folder there, ensure the packages in the list you obtained in the previous step matches what's in the bin folder.
Edit your export PATH string accordingly:
export PATH=$HOME/bin:/usr/local/bin:**$HOME/.npm/bin**:$PATH.
This worked for me!

Related

ng is not recognized as an internal or external command

Running windows 7 Professional 32bit.
I tried running npm install -g angular-cli both under normal or admin.
I also tried adding it to the Enviorment Variables under PATH: (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng) , with no success also.
What am i doing wrong?
I solved this problem in accordance with the figure:
run in cmd
npm install -g #angular/cli
and then
( open in Windows 10) Control Panel\All Control Panel Items\System
or accordance with the figure
step 1:
step 2 :
step3:
step4:
step5: add missing ng path
Here is new environment variable that you need add: C:\Users\PK\AppData\Roaming\npm\node_modules\#angular\cli\bin
Finally, restart all opened command prompts and try again.
For me it works with:
npm run ng <command>
Adding C:\Users\DELL\AppData\Roaming\npm to System Variable Path worked for me. Please find your appropriate file path to 'npm'
Also, check if you have added your angular-cli\bin path to the path variable.
I am using WIN 10, just figure it out for this problem.
Type the code below in cmd:
npm config get prefix
and copy&paste the path that you get it from the top into your computer environment variables-->user variables box --> path --> edit -- C:\Program Files\nodejs\node_global, your path may different.
Click Ok and reopen your cmd window, type in ng version, then it works! Cheers!
Just open your command prompt (run as administrator). Ensure node --v is 6.9.0 or higher and npm --v is 3.0.0 r higher.
After that run the following command:
npm install -g #angular/cli
Once angular is installed. you can see an entry of angular cli in the path
C:\Users\Dell\AppData\Roaming\npm\node_modules\#angular
Then try ng help. It will work.
1) Enter below command on command prompt
npm install -g #angular/cli
2) Make sure that C:\Users\_username_\AppData\Roaming\npm this path is not hidden.
3) Add C:\Users\_username_\AppData\Roaming\npm and
C:\Users\_username_\AppData\Roaming\npm \node_modules#angular\cli\bin to both enviroment variable path.
4) Open new command prompt and type ng help. It will work.
With a command
npm install -g #angular/cli#latest
It works fine, I am able to run ng command now.
I solved it few days ago, after having the same problem with other global modules, by adding to:
Environment Tables -> System variables -> Path:
C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin;C:\Program Files\MongoDB\Server\3.2\bin
Note that it must not have any spaces after ;
That turned out to be my problem.
I followed below steps for resolution for this issue in Windows 10:
First make sure you have installed Angular CLI . You can use below
to install same.
npm install -g #angular/cli#latest
Make sure that AppData is visible and navigate to path below.
C:\Users\rkota\AppData\Roaming\npm
Same path can be found by running below too:
npm config get prefix
Add the above path i.e. " C:\Users\rkota\AppData\Roaming\npm" in Environment variable PATH and make sure it got added by running path in command prompt.
Close command prompt and now try to run below:
ng --version
you will be able to see CLI version.
execute following lines in order to solve the issue for both not found and undefined version of ng
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
npm cache clean
npm install -g #angular/cli#latest
Instead of using the in-built command prompt better start using the NodeJS installed version of command prompt. Then it is going to work perfectly without any issues.
General problem is that OS tries to find the PATH variable with ng keyword and cannot find it.
For me, even after the steps #behrouzmoslem suggested in the top answers to this post I didn't manage to get it work, because after the launch of ng command OS started to respond, but opens up editor file by the path C:\Users\{username}\AppData\Roaming\npm\node_modules\#angular\cli\bin\ng which is actually funny. So, solution is:
Just use npx before any angular executables.
Eg : npx ng serve for serving the angular app or npx ng build --watch to build with watcher.
If you get the error even after following the above step. then try below.
Since it is a node script. I am using the below option to create as of now.
node C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng version
May be symbolic links are required. Not researched further.
On Further Research:
Set Path as : %PATH%;C:\Users\Administrator\AppData\Roaming\npm;
In Windows, npm.cmd file is in the above path. If the above Environment variable is set, you can execute as
ng version
ng init
Open cmd and type npm install -g #angular/cli
In environment variables, add either in the user variable or System variable "Path" value=C:\Users\your-user\.npm-packages\node_modules\.bin
In cmd: c:\>cd your-new-project-path
...\project-path\> ng new my-app
or ng all-ng-commands
I resolved by adding - %AppData%\npm\node_modules#angular\cli\bin\ path to my environment variables path
close cmd and open it again with admin right or reboot ur system.
for me it works only with the flag --force:
npm install -g #angular/cli --force
If everything is fine then you shoud see the folder node_modules in this path:
C:\Users\YOUR_USERNAME\AppData\Roaming\npm\
I faced same issue when i tried to install angular cli locally with command
npm install #angular/cli#latest
After that i got same issue
C:\Users\vi1kumar\Desktop\tus\ANGULAR\AngularForms>ng -v
'ng' is not recognized as an internal or external command,
operable program or batch file
Than i tried to install it globally
npm install -g #angular/cli#latest
In this case it worked I was wondering that is it not possible to install cli globally ?
After doing some research I found this article very helpful hope it will help someone facing similar issue
Working with multiple versions of Angular CLI
This one almost worked for me, but I had to use: %USERPROFILE%\AppData\Roaming\npm
. In Environment Variables.../System variables/Path
Then when I did CMD: "ng -v" I got the correct response for angular cli.
npm install -g #angular/cli helped for me instead of npm install #angular/cli
1- Install
$ npm install -g #angular/cli
2- Make sure where your ng.cmd is present.
3- Then add this path into variables.
I had the same problem on Windows 7, 64 bits running with npm v3.10.8.
I added the path as it was suggested: ( C:\Users.....(your user name)\AppData\Roaming\npm\node_modules\angular-cli\bin\ng) and uninstalled angular-cli.
After this, I cleared the npm cache by npm cache clean as prompted here https://blogs.msdn.microsoft.com/matt-harrington/2012/02/23/how-to-fix-node-js-npm-permission-problems/. This guarantees there are no leftovers.
Reinstalled angular-cli with npm install -g angular-cliand voila.
Hope that may be useful!
In my case I did below steps.
All Programs -> Node JS-> Right click on Node.js Command Prompt and select properties and from Target string at end copy below
/k "C:\Program Files\nodejs\nodevars.bat"
I launched Visual Studio Code and opened below file
C:\Users\gochinta\AppData\Roaming\Code\User\settings.json and gave below
// Place your settings in this file to overwrite the default settings
{
"terminal.integrated.shellArgs.windows":
["/k", "C:\\Program Files\\nodejs\\nodevars.bat"]
}
Now I typed ng -v in my Visual Studio Code Terminal window and it worked.
I was having the same issue when tried with the syntax "ng new " and solved that simply by updating the existing node version from 5.x.x to 8.x.x. After successful updation of node, the syntax worked perfectly for me. Please update the existing version of node. As it is clearly mentioned in angular documentation that these commands require the node version >= 6.9.x. For reference please check https://angular.io/guide/quickstart. It clearly states "Verify that you are running at least node 6.9.x and npm 3.x.x by running node -v and npm -v in a terminal/console window. Older versions produce errors, but newer versions are fine".
I faced same issue on x86, windows 7;
uninstalled #angular/cli
re-installed #angular/cli
checked & verified environmental variables (no problems there)...
Still same issue:
Solution was the .npmrc file at C:\Users{USERNAME}... change the prefix so that it reads "prefix=${APPDATA}\npm"... Thanks to this website for help in resolving it
For me something was wrong in the PATH enviroment variable. I removed all path related to npm and added at the start of PATH this folder:
c:\Users\<your-user-name>\AppData\Roaming\npm\
Make sure you have ; between paths.
I am facing same issue and it's get resolved. At my end reason is i install node and CLI using other user profile and now i am running ng command from other user login. Since node and cli installed using other user login node is not finding anything on C:\Users\<user name>\AppData\Roaming this path and that's why i am getting this error.
I run npm install -g #angular/cli command and restart my machine. Every thing is working fine.
Sometime in the future. Applicable to Windows 8.1 machine.
Run the following commands
npm install -g #angular/cli
Log out or restart your machine.
This should add the required env path, rather than doing it manually.
I also tried to play with cmd by setting environment variable path & etc, but simple answer is use nodejs command prompt.
So you no need to set environment variable path or anything. When you insalled nodejs it will give it's command prompt, by using that you us "ng" command, without any settings.
Since this question is still asked over and over again one year later I will post my answer here as well.
The clue (on Windows only) is to arrange the entries in the path variable right.
As the NPM wiki tells us:
Because the installer puts C:\Program Files (x86)\nodejs before C:\Users\\AppData\Roaming\npm on your PATH, it will always use version of npm installed with node instead of the version of npm you installed using npm -g install npm#<version>.
So your path variable will look something like:
…;C:\<path-to-node-installation>;%appdata%\npm;…
Now you have two possibilities:
Swap the two entries so it will look like
…;%appdata%\npm;C:\<path-to-node-installation>;…
This will load the npm version installed with npm (and not with node) and with the installed Angular CLI version.
If you (for whatever reason) like to use the npm version bundled with node, add the direct path to your global Angualr CLI version. After this your path variable should look like this: …;C:\Users\<username>\AppData\Roaming\npm\node_modules\#angular\cli;C:\<path-to-node-installation>;%appdata%\npm;…
or …;%appdata%\npm\node_modules\#angular\cli;C:\<path-to-node-installation>;%appdata%\npm;…
for the short form.
This worked for me since a while now.

Gulp command not found after install

I installed gulp(globally) and it looks like it worked because it ran this code:
├── tildify#0.2.0
├── interpret#0.3.5
├── pretty-hrtime#0.2.1
├── deprecated#0.0.1
├── archy#0.0.2
├── minimist#0.2.0
├── semver#2.3.2
├── orchestrator#0.3.7 (stream-consume#0.1.0, sequencify#0.0.7, end-of-stream#0.1.5)
├── chalk#0.5.1 (escape-string-regexp#1.0.1, ansi-styles#1.1.0, supports-color#0.2.0, strip-ansi#0.3.0, has-ansi#0.1.0)
├── gulp-util#2.2.20 (lodash._reinterpolate#2.4.1, dateformat#1.0.8-1.2.3, vinyl#0.2.3, through2#0.5.1, multipipe#0.1.1, lodash.template#2.4.1)
├── liftoff#0.12.0 (extend#1.2.1, minimist#0.1.0, resolve#0.7.4, findup-sync#0.1.3)
└── vinyl-fs#0.3.5 (graceful-fs#3.0.2, lodash#2.4.1, mkdirp#0.5.0, strip-bom#0.3.1, vinyl#0.2.3, through2#0.5.1, glob-watcher#0.0.6, glob-stream#3.1.14)
But when I type gulp it says -bash: gulp: command not found
Any idea what's going on?
Turns out that npm was installed in the wrong directory so I had to change the “npm config prefix” by running this code:
npm config set prefix /usr/local
Then I reinstalled gulp globally (with the -g param) and it worked properly.
This article is where I found the solution: http://webbb.be/blog/command-not-found-node-npm
Not sure why the question was down-voted, but I had the same issue and following the blog post recommended solve the issue. One thing I should add is that in my case, once I ran:
npm config set prefix /usr/local
I confirmed the npm root -g was pointing to /usr/local/lib/node_modules/npm, but in order to install gulp in /usr/local/lib/node_modules, I had to use sudo:
sudo npm install gulp -g
If you're using tcsh (which is my default shell on Mac OS X), you probably just need to type rehash into the shell just after the install completes:
npm install -g gulp
followed immediately by:
rehash
Otherwise, if this is your very first time installing gulp, your shell may not recognize that there's a new executable installed -- so you either need to start a new shell, or type rehash in the current shell.
(This is basically a one-time thing for each command you install globally.)
I realize that this is an old thread, but for Future-Me, and posterity, I figured I should add my two-cents around the "running npm as sudo" discussion. Disclaimer: I do not use Windows. These steps have only been proven on non-windows machines, both virtual and physical.
You can avoid the need to use sudo by changing the permission to npm's default directory.
How to: change permissions in order to run npm without sudo
Step 1: Find out where npm's default directory is.
To do this, open your terminal and run:
npm config get prefix
Step 2: Proceed, based on the output of that command:
Scenario One: npm's default directory is /usr/local
For most users, your output will show that npm's default directory is /usr/local, in which case you can skip to step 4 to update the permissions for the directory.
Scenario Two: npm's default directory is /usr or /Users/YOURUSERNAME/node_modules or /Something/Else/FishyLooking
If you find that npm's default directory is not /usr/local, but is instead something you can't explain or looks fishy, you should go to step 3 to change the default directory for npm, or you risk messing up your permissions on a much larger scale.
Step 3: Change npm's default directory:
There are a couple of ways to go about this, including creating a directory specifically for global installations and then adding that directory to your $PATH, but since /usr/local is probably already in your path, I think it's simpler to just change npm's default directory to that. Like so: npm config set prefix /usr/local
For more info on the other approaches I mentioned, see the npm docs here.
Step 4: Update the permissions on npm's default directory:
Once you've verified that npm's default directory is in a sensible location, you can update the permissions on it using the command:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Now you should be able to run npm <whatever> without sudo. Note: You may need to restart your terminal in order for these changes to take effect.
I had similar problem I did the following steps and it worked.Go to mac terminal and execute the commands,
1.npm config set prefix /usr/local
2.sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
This two commands will set the npm path right and you no longer have to use sudo in npm.
Next uninstall the gulp
npm uninstall gulp
Installl gulp again without sudo,
npm install gulp -g
This should work!!
I had this problem with getting "command not found" after install but I was installed into /usr/local as described in the solution above.
My problem seemed to be caused by me running the install with sudo. I did the following.
Removing gulp again with sudo
Changing the owner of /usr/local/lib/node_modules to my user
Installing gulp again without sudo. "npm install gulp -g"
If you are on Mac run use root privilege
sudo npm install gulp-cli --global
To check if it's installed run
gulp -v
CLI version: 2.2.0 (The output)
Local version: Unknown
You need to do this npm install --global gulp. It works for me and i also had this problem. It because you didn't install globally this package.
I got this working on Win10 using a combination of the answers from above and elsewhere. Posting here for others and future me.
I followed the instructions from here: https://gulpjs.com/docs/en/getting-started/quick-start but on the last step after typing gulp --version I got the message -bash: gulp: command not found
To fix this:
I added %AppData%\npm to my Path environment variable
Closed all gitbash (cmd, powershell, etc...) and restarted gitbash.
Then gulp --version worked
Also, found the below for reasons why not to install gulp globally and how to remove it (not sure if this is advisable though):
what does gulp-"cli" stands for?
How to uninstall Gulp CLI from NPM globally?
In my case adding sudo before npm install solved gulp command not found problem
sudo npm install
If you want to leave your prefix intact, just export it's bin dir to your PATH variable:
export PATH=$HOME/your-path/bin:$PATH
I added this line to my $HOME/.profile and sourced it.
Setting prefix to /usr/local makes you use sudo, so I like to have it in my user dir. You can check your prefix with npm prefix -g.
Behind corporate proxies the global command usually doesnt work , hence u can run the command where the gulp is installed locally.

gulp command not found - error after installing gulp

I've installed gulp both globally and locally using
npm install gulp
npm install gulp -g
npm install gulp-util
npm install gulp-util -g
When try to run gulp i get
'gulp' is not recognized as an internal or external command, operable program or batch file.
Running npm list gulp (or -g), I gulp#3.7.0 with the location of either my global or local gulp installation.
I've tried running node gulpfile.js pointed to my gulpfile, and it runs without error, and of course, it starts with require('gulp').
Any suggestions on getting gulp working on Windows(8.1)?
You forgot to install the gulp-cli package:
npm install -g gulp-cli
Then you can run the command "gulp" from the command line.
The issue and answer can be found in this question: https://stackoverflow.com/a/9588052/1041104
The npm modules such as gulp are not installed to the path. Thus are not found when you run them in the CMD.
If gulp has been installed globally, you can use the process below:
Create an environmental variable called NODE_PATH
Set it to: %AppData%\npm\node_modules or %AppData%\npm on windows 8-10
Close CMD, and Re-Open to get the new ENV variables
Running npm ls and npm ls -g shows that they are installed, but the CMD can not find them due to the missing link.
Be sure that you have gulp and gulp.cmd (use windows search)
Copy the path of gulp.cmd (C:\Users\XXXX\AppData\Roaming\npm)
Add this path to the Path envirement variable or edit PATH environment variable and add %APPDATA%\npm
Reopen cmd.
Add %APPDATA%\npm to front of Path, not end of the Path.
Install gulp globally.
npm install -g gulp
Install gulp locally in the project.
npm install gulp
Add below line in your package.json
"scripts": {
"gulp": "gulp"
}
Run gulp.
npm run gulp
This worked for me.
I am using Windows 8.1. I had the same problem.
I installed gulp using Node.js command prompt
npm install -g gulp
Then go to the required directory in Node.js command prompt and try
gulp -v
If you get gulp local version not found exit the current Node.js command prompt and try the above command in a new Node.js command prompt
I tried the NODE_PATH mentioned by #SteveLacy but the command prompt was still not able to detect gulp command
Had the same problem, not really best solution but install it globally:
npm install -g gulp
Of course it's best to still have it in package.json, so you can do the following to install it locally and add an entry into package.json:
npm install --save-dev gulp
Everything else (gulp plugins) install also locally.
The simple solution just do npm link gulp
I was having the same problem when trying to get gulp working on a co-workers VM. It seems the problem stems from the users folder.
Adding NODE_PATH in my environment variables didn't fix the problem.
If you edit your 'Path' variable in your system variables and add '%APPDATA%\npm' at the end of that, it should fix the problem... Unless you or somebody else npm installed gulp as another user than the one you're currently logged in as.
If you want it to be available for all users, put 'C:\Users\yourUser\AppData\Roaming\npm'(or where ever you have gulp) explicitly instead of using '%APPDATA%\npm'. You can also move the files to a more user-indifferent path.
Don't forget to start a new cmd prompt, because the one you have open won't get the new 'Path' variable automatically.
Now 'gulp'.
One right way:
Cmd + R : type "%appdata%"
Go to npm folder
Copy whole path like "C:\Users\Blah...\npm\"
Go to My Computer + Right Click "Properties"
Advanced System Settings (On the left)
Click on Environment Variables
Click on Edit Path
Add that "C:\Users\Blah...\npm\" to the end and type ";" after that
Click ok and reopen cmd
You should first install gulp as global using:
npm install gulp -g
Otherwise the path solution will not resolve the problem.
Then add the npm modules path to the PATH using:
PATH = %PATH%;%APPDATA%\npm
In my case it was that I had to install
gulp-cli by command npm -g install gulp-cli
Try to add to your PATH variable the following:
C:\Users\YOUR_USER\AppData\Roaming\npm
I had the same problem and I solved adding the path to my node modules.
I had a similar problem setting it up in windows 10. My answer is windows specific (look at the answers for modifying path in bash for a linux or OSX solution)
The core problem I had was that npm's folder was not registered in the path.
I originally tried changing this in cmd prompt.
setx path "%path%;%appdata$\npm"
Note that I used setx instead of set to ensure that the update to the environmental variable remains. Also note that it's a backslash.
This should work but for me it didn't because setx has a limit of only accepting 1024 characters... (yes it's nonsensical to me as well).
So try the above and if you get a warning like did about reaching the 1024 limit, then you can do the other way I ended up doing.
First while youre still in the console, type: echo %appdata%\npm ... this is your npm folder that you want to add to the path so add it to your clipboard.
You have to go into the registry and reach the following folder:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
Then append the 'Path' value with the npm folder path in your clipboard. Reboot to activate the new value and you should now be good to go.
Finally, just test it all out
>npm install -g gulp
>gulp
This ended up being a 'user' issue with me. I had installed npm and node on the system logged in as user1, then I set-up user2. I could run node, and I could run npm commnds, but could not run any npm packages from the command line.
I uninstalled node and npm, and reinstalled under the correct user in order to solve the problem. After that I can run packages from the command-line without issue.
The top answer did not work for me.
I am using a virtual machine that had a previous owner. The previous owner had an old version of npm installed. Using that, I was installed gulp globally with npm install -g gulp. Running the command gulp would return 'gulp' is not recognized as an internal or external command, operable program or batch file.. As I said, the top Answer did not fix my problem. I basically had to reinstall nodejs.
Solution
Re-download nodejs
npm install -g gulp
gulp -version
This fixed the problem for me.
I had v0.12.3 of Nodejs on Win7 x64 and ran into similar issues when I tried installing gulp. This worked for me:
Uninstalled Nodejs
Installed Nodejs v0.10.29
npm install -g npm
npm install -g gulp
The NodeJS installer appears to add the user/AppData/Roaming/npm path to the user environment path, which is appropriate.
Normally, the PATH environment variable at the command line is the combination of the user environment path and the system environment path.
However, if the user environment path + the system environment path is larger than about 1920 characters, Windows does not not combine the user and system paths - only the system environment path is used.
See: https://stackoverflow.com/a/21270921/301152
So, when you open the Advanced System Settings in Windows to edit your environment variables, take a look to see if the user/AppData/Roaming/npm path is already in your user environment PATH. If it is, then the problem is that your user + system paths are too long, causing Windows to ignore your user path. Trim your user and/or system path strings and gulp should work as installed.
If you can't find anything to trim away from your user and system paths, then add the user/AppData/Roaming/npm path to the system environment path and call it a hack.
I was facing the same problem after installation. So i tried running cmd with elevated privileges (admin) and it worked.
Screen capture:
Add this path in your Environment Variables PATH
C:\Users\USERNAME\AppData\Roaming\npm\
(Windows 10) I didn't like the path answers. I use choco package manager for node.js. Gulp would not fire for me unless it was:
Globally installed npm i -g gulp and local dir npm i --save-dev gulp
The problem persisted beyond this once, which was fixed by completely removing node.js and reinstalling it.
I didn't see any comments about local/global and node.js removal/reinstall.
This is most commonly because it is not found on environment variables as others have pointed out. This is what worked for me.
echo %PATH%
This will show you what's one your PATH environment variable. If node_modules is not there there do the following to add it from your APPDATA path.
PATH = %PATH%; %APPDATA%\npm
I resolved it by adding
C:\Users\[USER]\AppData\Roaming\npm
to PATH
and not
C:\Users\[USER]\AppData\Roaming\npm\node_modules
I already had the one condition from this answer (I don't know why)
https://stackoverflow.com/a/27295145/1175496
That is, my PATH already included %APPDATA%\npm
In my case, the problem was npm was not installing modules there (again, I don't know why)
Therefore I needed to do this:
$ npm config set prefix -g %APPDATA%/npm
After that, running
$ npm install -g gulp (or installing any other module) put the module in the place where PATH expects it.
This works for me:
npm link gulp
npm update
On my Windows 10 Enterprise, gulp was not installed in %AppData%, which is C:\Users\username\AppData\npm\node_modules on my machine, but in C:\Users\username\AppData\Local\npm\node_modules.
To get gulp to be picked up at the command prompt or in powershell, I added to the user PATH the value C:\Users\username\AppData\Local\npm. After that it worked like a charm. Naturally I had to close the command prompt or powershell window and re-open for the above to take effect.
Had gulp command not found problem in windows 10 and Adding "%AppData%\npm\node_modules" doesn't work for me.
Do this steps please:
After doing
npm install -g npm
And
npm install -g gulp
Add
C:\Users\YourUsername\npm
to Path in System Variables.
It Works for me after all solutions failed me.
Run npm install gulp -g
if you are using windows, please add the gulp's dir to PATH.
such like C:\Users\YOURNAME\AppData\Roaming\npm\node_modules\gulp
In windows:
Using your windows explorer, Navigate to your vagrant shared folder (I am using scotchbox by the way) e.g C:\scotchbox/public/gulpProject
In the address bar of the folder, type cmd and press Enter
Do your gulp installation npm install
In short:
You should add %NODE_PATH% to the system variable Path if the other answers don't work.
The reason:
The point is, command prompt only executes programs under the Path system variable, not the user variables. If you have NODE_PATH set as a user variable, add %NODE_PATH% to Path.
I asked here and got marked duplicate for a question with different intention :(
NPM Windows doesn't execute program under the User Variable path [duplicate]
In Windows:
Press the following two keys: Windows + r
Type control /name microsoft.system into the run dialog box that appears from the previous step.
Select Advanced System Settings from the left of the window pane
Click the Advanced tab on the system properties box that appears and click the Environment Variables button.
Edit the PATH User environment variable.
Click New on the edit environment variable window that pops up for the PATH variable and add the following: %APPDATA%\npm to the start of the PATH environment variable (as shown in the image below).
Close your Command Prompt and reopen it.

firebase-tools "-bash: firebase: command not found"

Excited that Firebase's hosting is now out of beta. Trying to get going with with the firebase-tools package and I've successfully installed it:
npm install -g firebase-tools
Trying to run any tool fails with
-bash: firebase: command not found
I've tried putting the following command in my .bash_profile without any luck
export PATH=/usr/local/share/npm/bin:$PATH
Any ideas? Pretty new to the command line in general.
Thanks!
Run code below with terminal,
alias firebase="`npm config get prefix`/bin/firebase"
Installing firebase-tools globally did the trick for me :
npm install -g firebase-tools
You should add the npm bin folder to your bash PATH variable. To do that, run:
npm get prefix
And it should output something like /home/your-username/npm-global or /home/your-username/npm-packages.
Then in your ~/.bashrc or ~/.bash_profile (if you're in a Mac) file, add:
export PATH="/home/your-username/npm-global/bin:$PATH" # Add npm bin PATH
Note the "/bin" after the npm get prefix result.
#mklement0 That answer looks good, but I'm worried it will be intimidating to someone who is so new to the command line. So I'm going to cherry-pick the most relevant piece of it.
#cienki Run this command to see what you should be putting in that PATH prefix in your .bash_profile file:
npm get prefix
by chance if you are using macOS with m1 chip
arch -x86_64 npm i -g firebase-tools
assuming that you haven't set the PATH
export PATH="`npm config get prefix`/bin:$PATH"
That's all and enjoy
On macOS: Use
curl -sL firebase.tools | upgrade=true bash
It worked for me
firebase -V
Using Windows 10, Bash
This worked for me:
npm get prefix // to find Path which for me it was C:\Users\User\AppData\Roaming\npm
search "Environment Variables" which located in "System Properties".
Under "System Variables", find the PATH variable, select it, and click "Edit". Click "New" and add the path found with the "npm get prefix" command earlier (which was for me C:\Users\User\AppData\Roaming\npm)
Then click "Ok"
Restart Bash
firebase --version //to check firebase version
Bruno's answer did the trick, I only needed to add a dot at npm-global in Ubuntu in .bashrc:
export PATH="/home/your-username/.npm-global/bin:$PATH" # Add npm bin PATH
Below command works for me on terminal
curl -sL firebase.tools | upgrade=true bash
This command install firebase tool for me
After installing:
$ npm install -g firebase-tools
$ firebase init
-bash: firebase: command not found
"If you are getting the above output then follow the below steps:"
For Windows Users:
type this cmd :
$ npm get prefix
C:\Users\Jeet\AppData\Roaming\npm [this is the location]
Now you have to set in enviorenment variable -> (windows+r) -> sysdm.cpl -> Advanced(tab) -> Environment Variables
-> under the System Variables -> click on path -> edit -> C:\Users\Jeet\AppData\Roaming\npm [paste] the above location -> apply - ok - ok.
Restart your bash terminal
Thanks!!!
For Mac OS Sierra:
$ sudo npm install -g firebase-tools
To stop other Node process use $ ps aux | grep node
If needed to upgrade or install emulator - $ npm install -g #google-cloud/functions-emulator
Ready to go $ firebase --version
For anyone using MacOS Catalina 10.15.2 getting the bash PATH variable fixed the issue for me.
Run:
npm get prefix
Then run:
export PATH=/Users/userid/.npm-global/bin:$PATH
Note: I recently upgraded from my old High Sierra MacBook Pro, and was confused as well.
For anyone using nvm the error could arise because you are on a different nvm version than you were on when you first installed firebase tools globally. That's what it was for me. When I restarted webstorm nvm switched to a different version.
Run nvm list to check the version you are on and run nvm use x.x.x to switch to the right version where you installed firebase tools originally.
This worked for me on Mac (same thing the others have been posting above, just for Mac):
go to your home folder in Finder (named after your user name, in my case "macbook")
press cmd+shift+dot (will reveal hidden files)
go the .npm-global/bin folder and copy its path (Finder menu -> View -> Show Path Bar, right click on the bin folder in the path bar -> "Copy 'bin' as Pathname")
open Terminal (by default the home folder) and go nano ~/.bash_profile
at the top of the file add export PATH="<cmd+v>:$PATH" (will look similar to this: export PATH="/Users/macbook/.npm-global/bin:$PATH")
save .bash_profile changes and restart Terminal, firebase command should work now
if you installing firebase-tools using
yarn global add firebase-tools
i got same error then i got answer and execute this
export PATH="$(yarn global bin):$PATH"
and then i can do firebase login pretty well
I am on Linux and installing the package with admin privileges resolved the problem:
sudo npm i -g firebase-tools
Simply reinstall node.js. This worked for me and fire command was recognized.
You forgot sudo type this
sudo npm install -g firebase-tools
problem solved.
I know most answers work for all generic 'command not found' errors. Basically by manually setting PATH variable but there's an easier way for this specific problem relating 'firebase command not found':
Try this cURL command and it will fix this issue for good and will minimise any user errors.
Install the Firebase CLI using the automatic install script
Run the following cURL command (Mac or Windows):
curl -sL https://firebase.tools | bash
Source: https://firebase.google.com/docs/cli#install-cli-windows, https://firebase.google.com/docs/cli#install-cli-mac-linux
This is for updated mac mac Os Catalina(10.15.1+) & on zsh.
Go to Terminal (vim .zprofile)
add this export PATH="/Users/Your Username/.npm-global/bin:$PATH"
Works for me!
Faced the same issue, am a newbie backend guy.
Used npm install firebase-tools
It doesn't install and you can't run.
I tried looking at the forums and here's what worked for me:
sudo npm install -g firebase-tools.
Then it asks for Permissions when you firebase login.
Am using Ubuntu.
After trying pretty much everything, only one worked for me (I'm on MacOs Catalina):
Try the following in your terminal:
curl -sL https://firebase.tools | bash
This will check the OS of your machine and then install everything else automatically and properly.
The command is from the official Firebase Documentation.
https://stackoverflow.com/a/60474459/1245341
After installing
$ npm install -g firebase-tools
Note the directory where it istalled What I did was locate the directory where firebase was installed. In my case C:\usr\local then I copied the three firebase files. I also went into the node_modules folder and copied the firebase tools folder. Then I went to my app directory in file manager and pasted the firebase files, then created a new node_modules folder and pasted the firebase-tools folder.
Now go to your cmd and run
$ firebase init
It should work
I tried a lot of things from here and from other forums, but what ended up working for me (and this is more of a work-around) was to download the binary and then open it and it set up all the firebase stuff for me.
However, I found that if I moved it after opening it once, it did not work. So first move it to wherever you want to leave it and then run the .exe.
This allowed me to skip configuring the PATH variable which was nice.
I'm on a Windows 10 Pro Education. Hope this helps someone who has a similar struggle.
Adding to Durul Dalkanat's answer,
Assuming you have executed npm install firebase-tools -g
Firstly get the output of the command of npm get prefix.
Open .bashrc file which is in the home directory and add alias <output of npm get prefix>/bin/firebase at the end of the file.
Run source .bashrc in the home directory.
Enjoy!
The alias of firebase will be the actual firebase path in the main system and this solution should work flawlessly.
if you're windows 8 user, one possible solution is to put the PATH in environment variables manualy...
On the Windows desktop, right-click My Computer.
In the pop-up menu, click Properties.
In the System Properties window, click the Advanced tab, and then click Environment Variables.
In the System Variables window, highlight Path, and click Edit.
In the Edit System Variables window, insert the cursor at the end of the Variable value field.
If the last character is not a semi-colon (;), add one.
After the final semi-colon, type the full path to the file you want to find.
For me it was: C:\Users\ 'username' \AppData\Roaming\npm
To get your path put this string in you command line:
$ npm get prefix
Click OK in each open window
I tried all the answers above, other SO answers, and GitHub answers but nothing worked. The only thing that worked for me was to save whatever was inside my index.js file temporarily somewhere else, delete the entire cloud functions folder, then reinstall and start everything from the very beginning.
After many hours trying everything the only thing what helped (on windows) was downloading and installing node again.
I found a solution.
npm i express firebase-tools
If you are admin on your PC, installing firebase and firebase-tools with -g flag should resolve the issue (the path will added to the global PATH variable) but if you are an admin, you may have to add that path yourself.
Seeking help from one of the top answer, issue this command will return the path where firebase is installed
npm config get prefix /bin/firebase
In my case the following is returned.
C:\Users\*user_name*\AppData\Roaming\npm
Copy that path (from first line) and visit this page on how to update path variable (Window + x then visit systems > Advance Settings). Here add a new entry in path and past that path there. Firebase command should work from command prompt every time without the use of alias required.

npm global path prefix

I am being more cautious than usual because I have been confused by the behavior of npm in the past.
I am on a Mac and have installed node.js through brew install node.
Now that I want to run jslint.js on the command-line as the command jslint I find that the canonical way to accomplish this is sudo npm install -g jslint which ran successfully with this output:
$ sudo npm install -g jslint
npm http GET https://registry.npmjs.org/jslint
npm http 200 https://registry.npmjs.org/jslint
npm http GET https://registry.npmjs.org/jslint/-/jslint-0.1.9.tgz
npm http 200 https://registry.npmjs.org/jslint/-/jslint-0.1.9.tgz
npm http GET https://registry.npmjs.org/nopt
npm http 200 https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz
npm http 200 https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz
npm http GET https://registry.npmjs.org/abbrev
npm http 200 https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/abbrev/-/abbrev-l.0.4.tgz
npm http 200 https://registry.npmjs.org/abbrev/-/abbrev-1.0.4.tgz
/usr/local/share/npm/bin/jslint -> /usr/local/share/npm/lib/node_modules/jslint/
bin/jslint.js
jslint#0.1.9 /usr/local/share/npm/lib/node_modules/jslint
└── nopt#1.0.10 (abbrev#1.0.4)
Subsequently
$ jslint ply.js
zsh: command not found: jslint
due to /usr/local/share/npm/bin not being in my $PATH.
1) Why did brew not install global npm bin path to path? Maybe it did, but something zsh does is messing it up. Where might I be able to find that?
2) Should I do this? (Append :/usr/local/share/npm/bin to the exported $PATH at the bottom of my ~/.zshrc)
It seems like this isn't the right way to do it because if I install something else later (using Homebrew or something) I'll be needing to append it to my zsh startup script to set the path. I guess in this particular instance it's just a matter of the npm install -g not making the right symlinks in a "proper" location (like /usr/local/bin maybe).
I think what I will do is manually build out symlinks inside /usr/local/bin for any programs that I have trouble with and it should be good enough for my purposes.
EDIT: I'm updating this in 2019, because this old question is popular but now outdated both in terms of my personal workflow and also in terms of how to best go about installing node and managing its various dependencies.
My personal workflow is now to use the installer obtained from nodejs.org to install node on systems. I actually trust this more than the homebrew package itself, because it knows best how to manage the files. If you want to change your system node from 8.10 to 10.15, whether on Mac or Windows, simply download the installer from nodejs.org for 10.15 for your OS. Attempting to upgrade node installed via homebrew has always proven to be a more difficult approach in my experience.
Also, the biggest thing to point out is that the use of sudo as shown in my npm install of jslint example above is highly discouraged; I am fairly certain that homebrew packages should never be installed or interacted with in any way using the superuser. It should not be necessary, and will lead to file permission headaches!
Furthermore I recommend ESLint over jslint, and have not used jslint in years.
Extending your PATH with:
export PATH=/usr/local/share/npm/bin:$PATH
isn't a terrible idea. Having said that, you shouldn't have to do it.
Run this:
npm config get prefix
The default on OS X is /usr/local, which means that npm will symlink binaries into /usr/local/bin, which should already be on your PATH (especially if you're using Homebrew).
So:
npm config set prefix /usr/local if it's something else, and
Don't use sudo with npm! According to the jslint docs, you should just be able to npm install it.
If you installed npm as sudo (sudo brew install), try reinstalling it with plain ol' brew install. Homebrew is supposed to help keep you sudo-free.
Spent a while on this issue, and the PATH switch wasn't helping. My problem was the Homebrew/node/npm bug found here - https://github.com/npm/npm/issues/3794
If you've already installed node using Homebrew, try ****Note per comments that this might not be safe. It worked for me but could have unintended consequences. It also appears that latest version of Homebrew properly installs npm. So likely I would try brew update, brew doctor, brew upgrade node etc before trying****:
npm update -gf
Or, if you want to install node with Homebrew and have npm work, use:
brew install node --without-npm
curl -L https://npmjs.org/install.sh | sh
I use brew and the prefix was already set to be:
$ npm config get prefix
/Users/[user]/.node
I did notice that the bin and lib folder were owned by root, which prevented the usual non sudo install, so I re-owned them to the user
$ cd /Users/[user]/.node
$ chown -R [user]:[group] lib
$ chown -R [user]:[group] bin
Then I just added the path to my .bash_profile which is located at /Users/[user]
PATH=$PATH:~/.node/bin
I managed to fix Vue Cli no command error by doing the following:
In terminal sudo nano ~/.bash_profile to edit your bash profile.
Add export PATH=$PATH:/Users/[your username]/.npm-packages/bin
Save file and restart terminal
Now you should be able to use vue create my-project and vue --version etc.
I did this after I installed the latest Vue Cli from https://cli.vuejs.org/
I generally use yarn, but I installed this globally with npm npm install -g #vue/cli. You can use yarn too if you'd like yarn global add #vue/cli
Note: you may have to uninstall it first globally if you already have it installed: npm uninstall -g vue-cli
Hope this helps!
brew should not require you to use sudo even when running npm with -g. This might actually create more problems down the road.
Typically, brew or port let you update you path so it doesn't risk messing up your .zshrc, .bashrc, .cshrc, or whatever flavor of shell you use.
In newer MacOS versions you need to edit the .zshrc file not .bash_profile:
In your terminal nano ~/.zshrc
then add the line:
export PATH=$PATH:/Users/[your username]/.npm-packages/bin
Try running:
PATH=$PATH:~/npm/bin
and then do a test by running express in the command line. This worked for me.
If you have linked the node packages using sudo command
Then go to the folder where node_modules are installed globally.
On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally. If you set the NODE_PATH environment variable to this path, the modules can be found by node.
Windows XP - %USERPROFILE%\Application Data\npm\node_modules
Windows 7 - %AppData%\npm\node_modules
and then run the command
ls -l
This will give the list of all global node_modules and you can easily see the linked node modules.
sudo brew is no longer an option so if you install with brew at this point you're going to get 2 really obnoxious things:
A: it likes to install into /usr/local/opts or according to this, /usr/local/shared. This isn't a big deal at first but i've had issues with node PATH especially when I installed lint.
B: you're kind of stuck with sudo commands until you either uninstall and install it this way or you can get the stack from Bitnami
I recommend this method over the stack option because it's ready to go if you have multiple projects. If you go with the premade MEAN stack you'll have to set up virtual hosts in httpd.conf (more of a pain in this stack than XAMPP)plust the usual update your extra/vhosts.conf and /etc/hosts for every additional project, unless you want to repoint and restart your server when you get done updatading things.
Any one got the same issue it's related to a conflict between brew and npm
Please check this solution https://gist.github.com/DanHerbert/9520689
I uninstalled node from homebrew on M1 Apple Silicon and instead used the Mac Installer from https://nodejs.org/en/download/. After doing that I was able to install with npm and npx.
Simple solution is ...
Just put below command :
sudo npm config get prefix
if it's not something like these /usr/local, than you need to fix it using below command.
sudo npm config set prefix /usr/local...
Now it's 100% working fine

Resources