Executables commands not found in -bash terminal [duplicate] - node.js

This question already has an answer here:
NPM -bash command not found
(1 answer)
Closed 6 years ago.
Using a Mac Os X Yosemite was trying generate some scaffolding and this is what comes back in the bash terminal
-bash: some_command: not found
This happens with most of my commands like run, serve etc when trying to generate or use certain executable commands. General alias’s and commands like mv, ls, rm etc work fine
I’ve checked my $PATH and it seems correct:
$ /bin/echo $PATH
/Users/user_name/.rbenv/shims:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/heroku/bin:/usr/local/bin:/usr/local/sbin:/usr/local/share/npm/bin:/Users/user_name/.rbenv/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin
I checked to make certain npm, node, yomen, grunt etc show as installed with -v and shows updated and installed.
I’ve checked my ~.bash_profile appears and aliases but all seems fine.
The best I can gage is it has something to do possibly with npm and or Node and possibly Homebrew. So I’ve uninstalled, reinstalled and researched any similar like questions out there but nothing seems to work. Hoping someone can point me in the right direction here since I am at a lost. And I am not the best at the environment set up. So might not be looking at something thats staring at me in the face. Thanks in advance.

Make sure to install whatever CLI tool you're trying to use first if you haven't already. For example:
npm install -g yo
That command installs yeoman into the global npm module directory. That directory should also be in your $PATH. To find the directory npm uses, type the following:
npm config get prefix
That will show you what directory npm is installing global modules to. In that directory there should be a bin/ directory with symlinks for any CLI tools that came with a global module you installed. That bin/ directory should be in your $PATH variable for bash to find command line scripts in there.
I'm using NVM to manage my node installations so when I run npm config get prefix my directory is: /Users/chev/.nvm/versions/node/v5.0.0. That's not the standard directory though. If you installed node with the default installer then yours will be different. When I do echo $PATH mine looks like this: /Users/chev/.nvm/versions/node/v5.0.0/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin. Directories in path are separated by colons (:).
A common problem with node on OSX is the need to use sudo with npm commands because of permissions issues in the default global npm modules directory. If you're having issues like that I suggest you also start using something like NVM. NVM allows you to install multiple node versions side by side, but even if you don't need that functionality it's still useful because it configures node & npm so that everything operates out of your home directory at ~/.nvm/ and avoids permission issues. No more sudo.

Related

How to install a global npm package using fnm (Fast Node Manager)?

My Problem
I have installed fnm (Fast Node Manager) from this github repo and it works all great except for installing global npm packages. For example, the well-known package nodemon is something I want installed globally and not im my node_modules project directory.
When installing the package globally there seems to be no problem:
And when checking the global package list, nodemon seems to be there:
But when running the command nodemon I get the following output:
As also seen in the fnm repository documentation there is a need to run this piece of code eval "$(fnm env --use-on-cd)"; on load in order to get fnm to work properly and this is what I have done in the .bashrc file.
Note
I am using windows 10, seems to be working on my mac laptop.
The Question
How can I have a global npm package installed for all or at least a single fnm node version? And what I mean by this, is that by running fnm use <NODE_VERION> you specify what node version to use as also seen in the repository documentation. I want to be able to run the nodemon command without it being installed in a project's node_modules directory.
You do not need to delete the multishells. The problem is the Git Bash path.
Fix is here: https://github.com/Schniz/fnm/issues/390
Put this in your .bashrc
eval $(fnm env | sed 1d)
export PATH=$(cygpath $FNM_MULTISHELL_PATH):$PATH
if [[ -f .node-version || -f .nvmrc ]]; then
fnm use
fi
As mentioned this actually worked on my OS X machine (aka my mac book pro) but not on my windows 10 computer. The solution I came up with after analyzing thoroughly the behaviour of fnm is the following:
Go to C:\Users\<YOUR_USER>\AppData\Local\fnm_multishells and delete the directory if it exists.
When downloading global packages do it via CMD or any terminal which isn't bash (or the terminal that has the "$(fnm env --use-on-cd)"; script) as this makes fnm then search for the global package in the wrong place.
This approach mitigates any path errors as I found that this was the core problem. As shown in the screenshot above when trying to run nodemon it looks for it in C:\Program Files\Git\Users\Valeri..... but this directory simply does not exist. After removing the directory mentioned in step 1 fnm stops looking for nodemon in that path and instead uses the one installed via CMD.
Essentially, the "$(fnm env --use-on-cd)"; script allows us to use fnm properly but at the same time causes this issue. Simply download global npm packages from a terminal that does not run this command.
Edit
I just had the same issue and to confirm you don't even need to delete the fnm_multishells directory. Just run npm -g remove <whatever> and install it via cmd or powershell. A command-line which does not run "$(fnm env --use-on-cd)"; on load.

Express command not found after setting installing globally

When I run sudo npm install -g express-generator:
/Users/myname/npm/bin/express -> /Users/myname/npm/lib/node_modules/express-generator/bin/express-cli.js
/Users/myname/npm/lib
└── express-generator#4.15.5
And when I run express:
express not found
Also, I thought it was interesting that when I run which npm:
/usr/local/bin/npm
That is the path.
It seems that whenever I try to install something like yeoman or this express generator globally, it never works.
It should also be noted that I am on an Mac running zsh.
Most likely your npm bin directory is not in the path. Try to list the files in that directory by ls -l /usr/local/share/npm/bin/.
If you find the express file, you can add that directory to the path by export PATH=/usr/local/share/npm/bin:$PATH. If not, most likely something went wrong with your installation and you can try installing the module again.
Running this in the command line:
export PATH=/usr/local/bin/npm:$PATH
Fixed the issue...for now. I'm not totally sure why that worked.
This affects Homebrew users using Node.js & npm
When you install Node.js using Homebrew it does not put npm on the PATH for you, however it suggests that you should do so.
Homebrew doesn't modify the user's environment or dotfiles. However, brew install node does print a message suggesting the user add that path to their PATH.
Source

'gulp' is not recognized as an internal or external command

I am trying to use Gulp and Node.Js to stream my process for minifying and concatenating CSS/JS files for production.
Here is what I have done.
I installed Node.Js on my Windows 7 machine.
Installed Gulp globally using this command npm install -g gulp
Then I added a new User variable called NODE_PATH set it to %AppData%\npm\node_modules
After closing and re-opening my command line, I tried to run a gulp task from the command line (i.e. gulp css). But that give me the following error
'gulp' is not recognized as an internal or external command
How can I get this to work?
When I opened the following path using the search bar in windows,
%AppData%\npm\node_modules I see the following two folders
gulp
gulp-cli
I've tried to add %AppData%\npm\node_modules to the Path variable on my system variable, but it did not take it because that variable reached it's max allowed character limit.
I removed couple of paths from my Path variable and added ;C:\Users\[MyWindowsUserName]\AppData\Roaming\npm\node_modules
but still not working.
I even tried to set the path at run time using this command
PATH=%PATH%;C:\Users\[MyWindowsUserName]\AppData\Roaming\npm\node_modules
then run gulp and still the same issues.
What am I missing here? What else do I need in order to get this to work?
I had similar issue when I installed locally initially(w/o -g). I reinstalled with -g (global) and then it worked.
npm install -g gulp
you should run gulp from folder where gulpfile.js is available.
I solved the problem by uninstalling NodeJs and gulp then re-installing both again.
To install gulp globally I executed the following command
npm install -g gulp
Go to My Computer>Properties>Advance System Settings>Environment Variables>
Under the variables of Administrator edit the PATH variable & change its value to "C:\Users\Username\AppData\Roaming\npm". Note: The username in the path will be the current Admin user's name that you have logged in with.
I had the same problem on windows 7. You must edit your path system variable manually.
Go to START -> edit the system environment variables -> Environment variables -> in system part find variables "Path" -> edit -> add new path after ";" to your file gulp.cmd directory some like ';C:\Users\YOURUSERNAME\AppData\Roaming\npm' -> click ok and close these windows -> restart your CLI -> enjoy
You may need to install the gulp-cli globally. Uninstall then re-install if you already have it:
npm uninstall -g gulp-cli
npm install -g gulp-cli
Sorry that was a typo. You can either add node_modules to the end of your user's global path variable, or maybe check the permissions associated with that folder (node _modules). The error doesn't seem like the last case, but I've encountered problems similar to yours. I find the first solution enough for most cases. Just go to environment variables and add the path to node_modules to the last part of your user's path variable. Note I'm saying user and not system.
Just add a semicolon to the end of the variable declaration and add the static path to your node_module folder. ( Ex c:\path\to\node_module)
Alternatively you could:
In your CMD
PATH=%PATH%;C:\\path\to\node_module
EDIT
The last solution will work as long as you don't close your CMD. So, use the first solution for a permanent change.
In my case, this problem occured because I did npm install with another system user in my project folder before. Gulp was already installed globally. After deleting folder /node_modules/ in my project, and running npm install with the current user, it worked.
You need to make sure, when you run command (install npm -g gulp), it will create install gulp on C:\ directory.
that directory should match with whatver npm path variable set in your java path.
just run path from command prompt, and verify this. if not, change your java class path variable wherever you gulp is instaled.
It should work.
If you have mysql install in your windows 10 try uninstall every myqsl app from your computer. Its work for me. exactly when i installed the mysql in my computer gulp command and some other commands stop working and then i have tried everything but not nothing worked for me.
I just encountered this on Windows 10 and the latest NodeJS (14.15.1). In my case our admins have our profiles and true "home" folder remotely mount onto our work machine(s). Npm wanted to put its cache over on the remote server and that has worked until this release.
I was unaware that npm has a .npmrc file available. I added one to my actual machine's C:\Users\my-id folder and it contains:
prefix=C:\Users\my-id\nodejs\npm
cache=c:\Users\my-id\nodejs\npm-cache
I also added these paths to my PATH environment variable.
I went to the APPDATA folder on my work machine and the remote "home" server and deleted all the npm related Roaming folders. I deleted the node_modules folder in my project.
I closed all open windows and reopened them. I brought up a command prompt in my project dir and re inited npm and reinstalled the modules I wanted.
After that everything is rolling along.
Just to add to #Vinod R's answer
Go to My Computer>Properties>Advance System Settings>Environment Variables>
Under the variables of Administrator edit the PATH variable & change its value to "C:\Users\Username\AppData\Roaming\npm". Note: The username in the path will be the current Admin user's name that you have logged in with.
After this, move the path to the top as shown in the image attached.
image for demostration
I was having the same exception with node v12.13.1,
Downgraded node to v10.15.3 and it works fine now.
The best solution, you can manage the multiple node versions using nvm installer. then, install the required node's version using below command
nvm install version
Use below command as a working node with mentioned version alone
nvm use version
now, you can use any version node without uninstalling previous installed node.

node user directory leading to command not found

I suipidly ran this script to stop having to use sudo on npm -g commands and now my node_modules are located at:
/Users/myusername/.npm-packages/lib/node_modules
when trying to run a commands i.e yo bower i get -bash: bower: command not found
Do I need to link this directory to the usr/bin?
In trying to sort this out I have run lots of commands and created symbolic links, I feel like my system is a real mess and I cannot really see what is going on? Help to ensure my system is clean would be really helpful.
Generally, it's a good idea to ensure that you do not need admin rights to run npm commands. The problem you're having, is that the directory where npm now installs its commmands (/Users/myusername/.npm-packges/bin) is not in your PATH. Your PATH is a list of directories where your shell searches for the commands you type.
You can add the directory to your path by adding the following line to the .bashrc file in your home directory (create it if it doesn't exist).
export PATH="${PATH}:/Users/myusername/.npm-packages/bin"
Open a new terminal, and bower should work again.
As an additional tip, I believe you're running on OS X? When installing Node.js using Homebrew, it is automatically installed in a proper way (no sudo needed to install packages globally and they will just work). Next time you're installing Node.js (or something else), Homebrew might be worth a try.

yeoman permission issue with nodejs and angular

I am trying to start an angular web app with yeoman but I get permission issue when trying to install the new generator. I can bypass and install generator with sudo but then I get the permission errors when running
**yo** angular
I deduce its because its trying to access npm modules that are global which the current user doesnt have permissions for, and I cant run Yo with sudo. I have done a lot of google searches and they all involve some type of hack with the NODE_PATH in the .bashrc or moving the node modules to the home directory. Has anyone found a simple solution for this issue.
Below is my problem in screenshots:
yo installs fine
when i try to install the generator without sudo complains..
install with sudo passes.
then finally when I try to run yo angular it breaks.. I believe its because yo runs as user and I have installed everything with sudo privileges. How can I get past this?
The reason it breaks, I guess, is because the whole directory tree was created as super-user.
The hacks you mentioned about using NODE_PATH and the home directory are not hacks. They exist for this same very reason. To tell node where to look for packages. And .bashrc is the place where you are supposed to change this kind shell variables.
Say you added ~/.node_modules to you NODE_PATH, then you can install all "global" in there. You could also change the permissions on /usr/local. But on linux world that is not recommended.
I also strongly recommend in not using global install with npm. Using -g and npm link is handy when developing but you shouldn't count on them. You can introduce subtle bugs in your code when you forget to add a package on you package.json but it is installed globally.
Instead of installing it globally, you can find all the packages executable on ./node_modules/.bin/ directory.
But lets say you don't want to be typing ./node_modules/.bin/yo all the time, you could create an alias on your .bashrc.
alias yo="$PWD/node_modules/.bin/yo"
and it would work like expected, and if there is no yo package installed, you get an error.

Resources