Deleted nvm now npm is not working - node.js

I installed nvm to update my node but then decided to uninstall. After updating my node via website, I am not able to get npm installed despite installing a new version of node and using:
sudo curl -L npmjs.org/install.sh | sudo sh
Here is the message I am getting:
-bash: /Users/SICNARF/.nvm/versions/node/v8.2.1/bin/npm: No such file or directory
I think I just have to change the command from non-existing nvm directory to (wherever its supposed to run).

Node.js version management: no subshells, no profile setup, no convoluted API, just simple.
Installation
npm install -g n
Example
$ n 8.2.1
https://www.npmjs.com/package/n

Related

Cant fix npm permissions mac mojave

I have spent the last few hours trying every tutorial out there on how to fix npm permissions on a mac.
NOTHING has worked thus far.
Steps I have taken
I have uninstalled node multiple times, tried running brew install node --without-npm then installing npm seperately.
I have tried to create my own npm-package file in my root directory and change the npm source and still that doesnt work.
I have tried what is detailed here https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
I have tried what is shown in this video https://www.youtube.com/watch?v=bxvybxYFq2o&t=154s
I have also tried a few other techniques all similar to above but nothing has worked.
Im on a 2015 macbook running a fresh install 0SX Mojave.
Any time I try to install a package it errors, and even if I use sudo, npm cant find the commands I'm entering for example if I
sudo npm install #angular/cli then try and use ng I get the command not found: ng
Any help would be appreciated. This question will be updated with methods used as they are suggested. Let me know If you need any more information.
I understand your frustration :(
These steps worked for me (from https://github.com/creationix/nvm/blob/master/README.md):
check if you have ~/.bash_profile file (home directory). I didn't. So I had to create it myself with:
touch ~/.bash_profile
Get NVM by running:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
them run
export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
verify nvm installation by running (you might need to restart terminal window before)
nvm --version
Install node via nvm - run:
nvm install node
(if you get version warning/error just follow the instructions(I had to run npm config delete prefix and then again nvm install node))
Install CLI:
npm install -g #angular/cli
verify installation:
ng -v
Hope it helps!

env: node: No such file or directory in mac

I'm searching it in google on how to show the version of node js or how I'm gonna work with npm?
If I do this
npm -v
even I already install it using brew install node. The result is always
env: node: No such file or directory
I already do a lot of command to solve for it, but failed.
these are the command that I already try:
sudo apt-get install nodejs-legacy
sudo ln -s /usr/local/bin/node /usr/bin/node
brew unlink node
brew link node
I can't start the task because of this. help me guys. This work before after I used this command brew link --overwrite node. Now I have problem, i cant work anymore with npm. I'm really new about this. I don't have any idea now on how to fix this.
Update
I already get the list using npm list command. I also get the idea here link but when I npm install inside the project. I alwayst get this "result env: node: No such file or directory",even I command npm -v but If i command it outside my project. It work the npm -v
I solved it this way:
$ brew uninstall --force node
$ brew uninstall --force npm
after it
$ brew install node
which suggested me to overwrite simlinks
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
rm '/usr/local/share/doc/node/gdbinit'
To force the link and overwrite all conflicting files:
brew link --overwrite node
after executing
$ brew link --overwrite node
everything worked again.
NOTE: Only mac users!
uninstall node completely with the commands
curl -ksO https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh
Or you could check out this website: How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
if this doesn't work, you need to remove node via control panel or any other method. As long as it gets removed.
Install node via this website: https://nodejs.org/en/download/
If you use nvm, you can use:
nvm install node
You can already check if it works, then you don't need to take the following steps with: npm -v and then node -v
if you have nvm installed:
command -v nvm
Uninstall npm using the following command:
sudo npm uninstall npm -g
Or, if that fails, get the npm source code, and do:
sudo make uninstall
If you have nvm installed, then use: nvm uninstall npm
Install npm using the following command: npm install -g grunt
I was getting this env: node: No such file or directory error when running the job through Jenkins.
What I did to fix it - added export PATH="$PATH:"/usr/local/bin/ at the beginning of the script that Jenkins job executes.
If you're switching from bash to oh my zsh, you will need to add nvm's path into the zshrc file.
#Zgpeace's answer here helped solve my issue (on IOS):
Open the .zshrc file. I used nano: nano ~/.zshrc
Add this into the file: export NVM_DIR=~/.nvm
Save changes by typing Ctrl+X --> Yes.
Reload the configuration. Type source $(brew --prefix nvm)/nvm.sh
Test by typing nvm --version.
You'll now be able to see the version. For e.g: 0.37.2
Thanks to this forum.
Sharing my notes below.
macOS Monterey
version 12.2.1
Chip Apple M1
$ brew uninstall --force node
$ brew uninstall --force npm
$ brew install node
$ brew link --overwrite node
$ brew doctor
$ brew cleanup
$ nvm --version
// 0.35.3
$ nvm use stable
// Now using node v17.6.0 (npm v8.5.1)
$ node -v
// v17.6.0
$ npm -v
// 8.5.1
I got such a problem after I upgraded my node version with brew. To fix the problem
1)run $brew doctor to check out if it is successfully installed or not
2) In case you missed clearing any node-related file before, such error log might pop up:
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built.
node
3) Now you are recommended to run brew link command to delete the original node-related files and overwrite new files - $ brew link node.
And that's it - everything works again !!!
It was nvm changing paths for me, this fixed it:
nvm use stable
I re-installed node through this link and it fixed it.
I think the issue was that I somehow got node to be in my /usr/bin instead of /usr/local/bin.
Let's see, I sorted that on a different way. in my case I had as path something like ~/.local/bin which seems that it is not the way it wants.
Try to use the full path, like /Users/tobias/.local/bin, I mean, change the PATH variable from ~/.local/bin to /Users/tobias/.local/bin or $HOME/.local/bin .
Now it works. 🙀🙀🙀
I get this error running npm start through PyCharm on Mac. For that the answer is to start PyCharm from the Terminal with open -a '/Applications/PyCharm.app/'. See https://stackoverflow.com/a/34017083/733092.
For Pycharm Professional, starting from the command line is different. Get the JetBrains Toolbox app, go to Settings, Generate Shell Script, and it will create a ~/pycharm_shell_scripts for you to run.
Working on MacOSx, maven exec not willing to execute a shell script that I could manually execute with desired result. Gave me the same error, solved it as well with
export PATH="$PATH:"/usr/local/bin/ at the beginning of the script
For mac user using the package manager homebrew:
-brew uninstall node
-brew uninstall npm
-brew doctor
-brew link node
-node -v (to check node version)
That's all you need.
For me, this error occurred when I tried to install a package with sudo npm. This fixed it:
sudo env PATH="$PATH:/usr/local/bin/" npm <rest of command>
I was using fish shell and encountered this problem on my m1 macbook air.
install nvm omf install nvm
add nvm to path by creating this file ~/.config/fish/functions/nvm.fish
I use vim so vim ~/.config/fish/functions/nvm.fish
function nvm
bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end
install node again nvm install node
It worked for me after that, :) hopefully it does for you too
credit https://eshlox.net/2019/01/27/how-to-use-nvm-with-fish-shell
If you just installed/modified node and if intellij/webstorm or your shell is throwing this error, it's because it has not sourced the environment variables, try restarting the IDE/shell.
I also face this issue on mac. I had installed node using brew. I was able to resolve the issue by following these steps:
uninstall node using the command: brew uninstall --force node
uninstall npm using the command: brew uninstall --force npm
Then install node using the installer provided on the following link: https://nodejs.org/en/download/
Just did an update on my Mac OS which switched my .bash to /zshrc. Here is what I added to my ~/.zshrc file:
export NVM_DIR="/Users/< my name >/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # this loads nvm
Then I did a $ source ~/.zshrc and it refreshed those values.
Double checked my work with nvm --version and it was all good.
just run cmd:
% npm
before
% npx install-peerdeps --dev eslint-config-airbnb
on Mac m1 pro
Kept getting this error, found it it's because NVM wasn't using any version of node. I didn't set this but after using these commands it seemed to fix the error
nvm install lts/*
nvm use lts/*

NPM not found when using NVM

I have installed node/npm using the nvm documentation.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
Then:
nvm install node
At this point node is working but the npm command result with:
npm: command not found
How can I have npm to work correctly ?
I found out that this was a conflict with a previous versions of npm that have not been removed properly despite a apt-get remove node.
I solved it by reinstalling npm from scratch:
rm -R ~/.npm ~/.nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
nvm install node
I found the solution here.
If you run NVM-Windows, don't forget to run nvm on. (this solve the problem as title for me.)
I fixed this by doing this command:
$ command -v npm
and then reopen the shell window.
I solved it by uninstalling all problematic node versions (e.g. v14 below) and reinstalling it.
The problem:
node --version; npm --version;
v14.17.1
Command 'npm' not found, but can be installed with:
sudo apt install npm
The solution:
nvm deactivate
echo "All versions BEFORE:"
nvm_ls
# uninstall all 14.* versions
for v in $(nvm_ls 14); do nvm uninstall $v; done
echo "All versions AFTER:"
nvm_ls
# reinstall version 14
nvm install 14
# and now it has npm too
node --version; npm --version
which node; which npm
# v14.17.1
# 6.14.13
# /home/user/.nvm/versions/node/v14.17.1/bin/node
# /home/user/.nvm/versions/node/v14.17.1/bin/npm
If you use Windows OS, make sure you removed the existing nodejs and npm.
In my case, it worked well after I remove the C:/Program Files/nodejs.
Reference is here.
During nvm installation, make sure the selected path must NOT exist.
This problem especially happens in windows which happens because of missing admin rights for cmd.
If you are using Git bash
Go in installation directory e.g C:\Program Files\Git
Right click properties -> compatibility.
Tick the checkbox with label -> Run as administrator.
Run the git bash again & execute npm list and then npm use 'version_to_be_used'
Same goes for Cmd
One possible reason is the NVM symlink is invalid.
But first, check if both NVM_HOME & NVM_SYMLINK is already set in environment path.
If not, maybe some problem with your nvm installation and u might want to reinstall.
Using explorer, open the symlink folder to check if the folder is valid.Default Symlink path in Windows: C:\Program Files\nodejs. Symlink appears as a normal shortcut in Windows explorer.
If you see node files in there, then you're fine.
If the folder is invalid, delete the symlink.
Then, execute nvm ls and nvm use <desired node version>, this step will re-create the correct symlink.
Restart CMD and test nvm current, node -v, npm -v
For Windows:
nvm creating symlink from installed node path like c:\program files\node to the c:\users<your user>\AppData\nvm<node ver>
So check:
Your basic node path in the PATH variable.
Your npm is inside c:\users<your user>\AppData\nvm<node ver>\nmp and this path is also int the PATH variable.
You could also run
source ~/.bashrc
and try to run again on the same bash terminal where you downloaded the install.sh the command:
npm -v
I went through a similar issue recently and solved it by setting the npm mirror to npm_mirror https://github.com/npm/cli/archive/refs/tags/
The default npm mirror (https://github.com/npm/cli/archive) was a broken link.
so run
nvm npm_mirror https://github.com/npm/cli/archive/refs/tags/
I had the same issue while any new terminal instance started up the message 'npm not found' was shown. I noticed that I had defined (probably) custom paths to npm and node in ~/.bashrc. Deleting them (keeping the paths for nvm) resolved the problem.
This helped me: https://github.com/coreybutler/nvm-windows/issues/548#issuecomment-768297716 Adding quotes to NVM_SYMLINK environment variable: "C:\Program Files\nodejs" instead of C:\Program Files\nodejs.
Install node using node source distribution:
curl -sL https://deb.nodesource.com/setup_[version].x | bash -
apt-get install -y nodejs
[version] = the wanted version. See the repository to choose the correct: NodeSource Node.js Binary Distributions

Sudo user not using same node version

I have a strange issue on my server, when ever i try to install packages with npm that require sudo I run into issues and i have discovered that my su and regular user use different node versions.
$ node -v i get node version 0.10.x
But when i do:
$ sudo node -v i get node version 0.6.x
My su user for some reason is using a different node version than what i normally use and this causes compatibility issues when I npm install packages that require sudo.
I have tried sudo apt-get upgrade nodejs at no luck. how do i make su user use same node version as my regular user.
run ll /usr/bin/node if this file exist, simply run rm /usr/local/bin/node from the regular user
explanation
If you'd run which node from regular user you will probably see it points to the user local bin directory
which node
/usr/local/bin/node
this means that the regular user installed another node version locally.
to let the same node version apply to all users, this command should show you usr bin (not local).
which node
/usr/bin/node
by deleting the link from /usr/local/bin/node it will automatically start using /usr/bin/node
Try running sudo with the environment of the user:
sudo -E node -v
I experienced this problem right after upgrading to a newer version of node (6 -> 7)
The above solution did not work for me as I do not the file /usr/local/bin/node but I was in fact getting different verions from running npm --version and sudo npm --version
https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation
The answer states that bash was caching the older version of node.
simply running hash -d npm

How do I know whether I have Node.js and npm successfully installed on Ubuntu 14.04?

I installed Node.js with these instructions and it seemed successful:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Then I installed npm with these instructions:
sudo curl https://www.npmjs.org/install.sh | sh
The nodejs installation seemed to work without errors but the npm command gave me a lot of errors. But it seems like they are installed because when I test what version I have they both come up:
nodejs -v
v0.10.30
npm -v
1.4.21
So If this doesn't tell me that I have both programs successfully installed, which I assume I do not, how do I know?
I think your tests tell that both or properly installed.
But you can try just type node in terminal & it should open a node shell, where you can check by running basic commands.
Current distributions of node.js (including the one you downloaded) already include npm. So maybe installing npm manually is one source of your errors. Beware that usually you run "npm install" with the permissions of a regular user. There are only some npm-based utilities that are to be installed with root permissions and the '-g' (global) command line switch.
On linux if you wish to install node.js and npm as yourself NOT root :
to start fresh remove prior node.js and npm installs as well as these :
~/.npmrc
~/.npm
~/tmp
~/.npm-init.js
create your ~/bin/ directory if not already created :
mkdir ${HOME}/bin
download source from : http://nodejs.org/download/
cd node-v0.10.30/
./configure --prefix=${HOME}/bin/nodejs
make -j8
make install
which puts it into dir defined by above --prefix
export PATH=${HOME}/bin/nodejs/bin:$PATH
define NODE_PATH so node can find dir for modules otherwise
npm install xxx will put newly installed module into dir in curr dir :
export NODE_PATH=${HOME}/bin/nodejs/lib/node_modules
do above AND use syntax :
npm install xxxxx -g
always use the -g for global which puts package xxxxx into $NODE_PATH
NOTE - nodejs install gives you npm as well :
ls -la ${HOME}/bin/nodejs/bin

Resources