npm install zsh: command not found: npm - node.js

I just reinstalled node on my laptop and trying to install packaged in project. I installed node via brew and Im using MacOS.
npm install
zsh: command not found: npm

The solution below actually solved my issue
https://superuser.com/questions/1403007/zsh-npm-node-nvm-command-not-found-after-installing-ohmyzsh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# This loads nvm bash_completion
this line of code on your .zshrc file to do that type vim ~/.zshrc than add the following lines in the bottom and to save the file click ctrl than press :wq! to save file in vim you can also use nano

Your binaries for npm are in /usr/local/share/npm/bin. Is this in your path environment variable?
If not export it at ~/.zshrc with export PATH=/usr/local/share/npm/bin:$PATH.

For me, I encountered the same issue as you did.
How I fixed:
First, checking whether npm is installed or not by checking its version:
npm --version
If the terminal still shows no npm not found, then type:
nvm install --lts
This command will trigger updating node package manager to the latest version.
Hope it helps.

You should run nvm use node every time you startup a new terminal.

Related

Problem choosing node version in Terminal - MacOS Ventura

Whenever I start a new session in iTerm or the Terminal in MacOS Ventura, I get the system label on the right.
A problem I'm facing is that whenever I want to change the node version, it cannot be done. It's always tied to the system version.
This is when I run nvm list. For default it's the right value: 16.18.1. But when I run nvm use default, and run nvm list again, I still see system as the selected version.
Does anyone know why is still using the system one, instead of the default?
I have no idea about the terminal prompt that appears on the right side.
I had the same issue, and I just added the below lines to the .zshrc file:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion
To use the latest version or the version that I installed on my machine, I tried the following:
nvm use <node_version>
I hope this helps!

/lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)

When I push the code to Github it automatically builds it and start the application on AWS through CodeDeploy with a application_start.sh script file that has the following code:
#!/bin/bash
#give permission for everything in the express-app directory
sudo chmod -R 777 /directory/backend
#navigate into our working directory where we have all our files OR exit
cd /directory/backend || exit
#add npm and node to path
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # loads nvm bash_completion
#install node modules
npm install
npm install pm2#latest -g
#pm2 stop all
pm2 stop backend
pm2 start ecosystem.config.js --env prodaws
This is the error it shows
127 exit code is "File or Directory Not Found"
I have a nother script that runs before the application_start.sh that installs node, I tried installing a more stable version with nvm install --lt but it did not change anything even the node verison
The only solution to this is to change the Operating System, Amazon Linux 2 does not upgrade those libraries to the latest version.
Changing the OS was also suggested by the Amazon Support team check out this article where I described in detail what happened.

How to install npm after it uninstalled itself?

I was recommended to run sudo npm install -g npm and so I did, now npm is gone!
It doesn't exist in the directory either /usr/local/lib/node_modules/.
Is there a way to install it back?
edit
I have node installed v14.17.0
you can use NVM(nodejs version manager) simply by running this command :
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
and
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
now you can download any version of nodejs and use it into the single project or globally without problems
if you need to download any version you can do it by the comand :
nvm install 14
now you have npm and node 14, but if you need to use it into the project you can do it by the command : nvm use 14
now you can switch between node(or npm) versions without any problem
npm comes with nodejs, you can just install nodejs using your OS.
See the link below
https://nodejs.org/en/download/
Once you install nodejs, npm will be installed.

NVM managed npm globally installed packages return command not found

I have nvm installed to manage my node versions. If I install a package globally, npm install -g fkill, then run fkill, I get the error zsh: command not found: fkill.
Here are some commands run to help with debugging this
$ npm root -g
/home/jchi/.nvm/versions/node/v10.15.3/lib/node_modules
Looking at my PATH...
$ echo $PATH
/home/jchi/.pyenv/shims:/home/jchi/.pyenv/bin:/home/jchi/.nix-profile/bin:/home/jchi/.autojump/bin:/home/jchi/.nvm/versions/node/v10.15.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
I do not see the output of npm root -g in my PATH.
I assume is nvm's responsibility to add that to my path so globally installed packages can be run. So I look at what I have in my .zshrc that kickstarts nvm.
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
105 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Suggestions appreciated
Looking at your PATH, you do have the nvm bin folder under your PATH.
/home/jchi/.nvm/versions/node/v10.15.3/bin
I would suggest to check if you have prefix related settings in ~/.npmrc.
If you have any prefix settings, please remove it.
Then try running npm install -g fkill again.
One way to fix this is to add your NVM node bin to your path.
What node version are you using? node --version
Add the line below to your .bashrc (replace VERSION with what you got in step 1)
export PATH="$HOME/.nvm/versions/node/VERSION/bin:$PATH"
Example:
export PATH="$HOME/.nvm/versions/node/v16.1.0/bin:$PATH"
When you refresh your terminal (. ~/.bashrc or re-opening terminal), your global Node commands should work now.
Unfortunately, it seems this needs to be done for each version of Node you use.
In my case, I had a package (let's call it cat-hat) installed globally on Node 14 using NVM (verified by checking .nvm/versions/node/v14.17.6/lib/node_modules/cat-hat) but I was getting zsh: command not found when trying to run it in my command line.
The issue in my case was that cat-hat only runs OK on node versions below 13. This can be verified in the package.json engines.node field.
I fixed this by changing to node 12, and installing cat-hat again for v12, and it worked as expected.

By restarting system terminal does not recognize npm and node commands

I have installed node and npm by nvm; At the end of instaling nvm, below message was shown:
Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
So I run that command and use nvm, install node versions and npm.
But when I restart my system, I have to run above command otherwise terminal says command not found.
What is the problem and how can I fix it?
The nvm installation should have added a couple of lines to your shell initialization script that makes sure to initialize nvm in every new shell, but for some reason this seems to have not happened.
Assuming that you're using bash, try adding these lines to your ~/.bash_profile
export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"
Then start a new terminal session and see if that does the trick.
Another thing that could be worth double-checking is to see if you have any installed node version aliased as the default one. I'm not sure what nvm does if you don't have a default version specified (if that's even possible). Run nvm ls and see you you have default pointing to any installed version of Node. If not, then set that up by running nvm alias default [version-number].

Resources