Npm command not found after restart

The npm command continues to be unrecognized after rebooting the computer:

 -bash: npm: command not found 

The node command is still working fine, but just npm not working. I need to reinstall Node.js from the main site for it to work again.

~/bin added to my $PATH in my .bash_profile with:

 export PATH="$HOME/bin:$PATH" 

Edit: I also use the full mathiasbynens / dotfiles , which controls its own version, interestingly there is a conflict here.

+6
source share
6 answers

I have no explanation, but a few pointers:

As @LaurentPerrin reports, node (via the official installer package) is installed on /usr/local/bin .
(Why are you mentioning ~/bin ?)

Please note that different rules apply if you use user level settings through node.js nvm version manager , in which case [symbolic links to] executable files are placed in ~/.nvm/v{version}/bin

Thus, the node executable should be /usr/local/bin/node .

Is this (only) what you see when you run which -a node ?

The executable node is placed directly in /usr/local/bin , while npm is just a symbolic link that points to /usr/local/lib/node_modules/npm/bin/npm-cli.js , which is an executable node script with the shebang line #!/usr/bin/env node .

At startup

 ls -l /usr/local/bin/npm 

you should see something like

 lrwxr-xr-x 1 root wheel 38 Dec 13 11:52 /usr/local/bin/npm -> \ ../lib/node_modules/npm/bin/npm-cli.js 

See if the symlink exists and points to the right file.

If this still doesn't work, try calling npm-cli.js and see what happens (this should show the npm command line help):

 /usr/local/lib/node_modules/npm/bin/npm-cli.js help 
+4
source

According to the nvm readme file , try running this once:

 nvm alias default stable 

In this case, the default version of Node will be installed, which will be used in any new shell.

+3
source

On OSX, the node is installed on /usr/local/bin , which should be in your path. Change /edit/paths as root ( sudo nano /etc/paths ) and make sure it is on the first line. It should look like this:

 /usr/local/bin /usr/bin /bin /usr/sbin /sbin 

You can then force bash to update the paths by doing: source /etc/profile .

+1
source

I had the same problem (on OSX). Not sure if this solution is for you, but I found npm here:

 .nvm/v0.10.22/bin 

or based on your version

 .nvm/v0.10.21/bin 

Then I just printed out my working directory and added that in my path. Therefore, for me, when I opened the terminal:

 cd .nvm/v0.10.22/bin pwd >> /path/to/.nvm/v0.10.22/bin 

Hope this helps.

0
source

I am using nvm to install node.js. I solve this by adding $HOME/.nvm/v0.10.25/bin to $PATH . Therefore, the problem is that the path was not found.

0
source

I have the same problem. My solution is to use sudo ... I assume this is due to a resolution problem.

0
source

Source: https://habr.com/ru/post/957981/


All Articles