Npm updates sucessfully, but still shows old version - npm

When I do a npm -v I see that I am still on 5.6.0. And keep getting prompts to do a npm i npm.
But I've done a sudo npm install npm#latest -g and double checked with a npm outdated -g --depth=0 to see that my global npm is at the latest already (6.0.0).
How do I resolve this conflict? Is the npm I'm using the latest or is it still the old one? Is it because my global is linked incorrectly or something?

Try closing the Terminal - once you open it again it should work, worked for me well.
*IvanD wrote this solution in a comment to the original post, I thought it's worth an answer post.

I can 100% vouch this works.
I got this from someone who teaches node.js.
Give NVM (Node Version Manager) a try. Do the commands in the following ordrer:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
command -v nvm
nvm install node
finally confirm that the update was successful
npm -v

Let's do a better solution if all of the mention methods not help you:
You need to install nvm (Node Version Manager)
After that just run:
nvm install 14
list your versions to see is version installed
nvm ls
and you will get list like this:
v10.2.0
v12.18.3
-> v14.10.0
system
default -> 14.10.0 (-> v14.10.0)
node -> stable (-> v14.10.0) (default)
stable -> 14.10 (-> v14.10.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> v12.18.3)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.22.0 (-> N/A)
lts/erbium -> v12.18.3
Switch default version like this:
nvm alias default 14.10.0
And check:
node -v
If print v14.10.0 you are ready to rock, if not:
nvm use 14
and check again.
This need to work like a charm and you will be happy.

Check your /usr/local/lib folder. I had the same problem and a node_modules folder in here. After removing it and rerunning [sudo] npm install npm#latest -g it showed and used the correct version.

sudo npm install -g n
If you want latest stable version
sudo n stable
If you want the latest version
sudo n latest
Then restart computer

I had this issue today with Node installer node-v10.16.0-x64.msi. Even after installing it I got the node version from npm -v as 3.10... and my react app would fail to start :(
It seems that node creates a folder in APPDATA at %AppData%\Roaming\npm
There was an old npm.exe lying there and this was in my Windows Path at user level. The user level Path overrides the system level Path where the new installer had added its path. The user override caused the new npm to not be found. Solution: Shift-Delete %AppData%\Roaming\npm ! :D Remove and reinstall with node-v10.16.0-x64.msi
Now npm -v gives 6.9.0!

If you have tried all the mentioned approach like :-
sudo npm install -g n
sudo n stable
or
sudo npm install npm#latest -g
still npm -v showing you the older version, once try to close your terminal and open a new one and check.

I found this command line that worked for me.
Update from version 12.18 to the latest version 15.2 correctly.
I hope this is useful:
nvm install node --reinstall-packages-from=node

I think your question is replecated and already has an answer.
First, The LTS and current version of NPM is 5.6.0 for both Node 8.11.1 (LTS) and Node 10.0.0 (Latest current version) according to the official documentation.
Otherwise, sudo npm install npm#latest -g should install the latest version NPM globally.

Search for a node_modules folder in your home directory, rename it or delete it, then try again.

First uninstall your installed nodejs from Control Panel\All Control Panel Items\Programs and Features.
Delete nodejs folder from the Program Files (x86) folder.
Now install new version and check it once.

Though this is an old question and the answer might not be relevant but I found myself into such situation many time, sometimes restarting the server is not a solution because other process will get effected. So you need to refresh the terminal without actually restarting the server and for that you may run exec bash and that will certainly help.

I was facing the same error today.Updated npm version does not reflect.
This is how I resolved it.
A lot of post suggested to use the command npm cache clean --f. But, it did not work for me. Hence, I deleted the "npm" and "npm-cache" folders from the location C:\Users\SearchYourUserName\AppData\Roaming
Uninstalled the existing node.
Re-Installed node version v10.x.x. I downloaded the node-v10.22.1-x64.msi file from https://nodejs.org/dist/latest-v10.x/ and installed it.
Then checked the npm version. It had worked.

Actually this could be happening due to mistakes like you installing packages using yarn ex:
// update the version number in package.json then
yarn install
and trying to run scripts using npm like
npm run start
Actually I did this mistake.
So make sure to use either yarn or npm, but not both.

I faced a similar issue. I had node v14.15.4 installed on ubuntu 18, but when i used node -v it showed v11.0.0.
To check all the node versions available on your system using nvm, use
nvm ls
To set the newly installed node version as the default, use
nvm alias default <version>
Then, just close the terminal and open a new terminal to check the node version.

Problem summary
npm -v # 6.xx
npm install npm#latest -g
npm -v # still the same, but should be 7.xx
Solution based on the answer of fypnlp.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
The terminal now wants to configure some ~/.zshrc file which I don't have on my Mac yet. So let’s create it
nano ~/.zshrc
and paste
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Now restart the terminal and run
command -v nvm # should return "nvm"
nvm install node
npm -v # now it’s 7.xx yay!

I have this same symptom but none of the answers helped and I finally found the issue.
It may not be exactly the same as the OP's but I think it is along the same lines. #Kelvin Zhao's solution of un-installing and re-installing worked for him but not for me so this might be useful for others.
My issue ended up being that I use brew and (I can't remember how exactly) but I seem to be have an old version in the brew Celler.
Brew didn't know about it, or couldn't tell me as I do a brew uninstall node and it says its doesn't exist.
When I run node -v or npm -v I get the old versions.
I uninstalled and reinstalled using brew and npm and sudo npm etc didn't do it. it showed the correct versions being installed but node -v still showed the old.
Turns out there is a version in my /usr/local/Celler directory named node#14.
So running brew uninstall node#14 got rid of that and now node -v doesn't work anymore.
Now re-installing node works. brew install node
More info for further details for those interested.
I wanted to find out where I still had node installed so I did echo $PATH as it had to be somewhere in the path else node -v wouldn't be recognised.
Turns out I had /usr/local/opt/node#14 in my path (which linked to /usr/local/Celler/node#14)
That is how I found it.
And now I think I remember how it got there. I'm 90% sure that I did an upgrade of node and brew asked what to do with the old version and I think I said to keep it.
And that was my mistake that lead me here (and where I think OP's situation differs)

In my case, I wanted to use Version 18 and it was showing 16. I'm using homebrew on my mac and the command that worked for me was the following:
brew uninstall node#16
And voila the version that was showing after is 18.

I had issue with VS Code when I did nvm alias in its own terminal, even after ran alias command, the version kept switching back to old version even I open a new terminal within the VS Code. But as stupid as it sounds, close and reopen the vscode for me worked, after I set the version in an independent terminal.

Related

How to fix 'command not found' for aws-cdk after running the npm install

I am trying to install the aws-cdk and in the terminal and I run the npm install -g aws-cdk. As stated here After npm runs, I get:
/usr/local/Cellar/node/9.8.0/bin/cdk -> /usr/local/Cellar/node/9.8.0/lib/node_modules/aws-cdk/bin/cdk
+ aws-cdk#0.31.0
updated 1 package in 1.636s
If I try to run cdk I get:
zsh: command not found: cdk
Installing as root worked for me:
sudo npm install -g aws-cdk
Make sure /usr/local/Cellar/node/9.8.0/bin is in your PATH
In my case, I added this to the end of my .bash_profile:
export PATH=$PATH:$(npm get prefix)/bin.
I did that based on information from a different thread.
If you're using nvm to manage your node versions, make sure that the CDK package is being installed in the same version of node you're currently using or the version you want to use.
The OP noted their CDK was getting installed in node/9.8.0:
Check the current node version running: nvm current.
If you see that the CDK installation location is different than the node version indicated by nvm current, you'll need to switch your node version using:
nvm use <node-version-where-cdk-is-installed>
In the OP's case, this would be nvm use 9.8.0.
What worked for me in mac was adding to the path the bin directory of globally installed node modules.
Install aws-cdk by:
npm install -g aws-cdk
Try to run it
cdk
no command found error
make or edit your .zshrc file in your user directory
add line to .zshrc with export PATH=$PATH:/{your_user_path}/.npm-global/bin
execute it source .zshrc
now cdk should work
Pay attention that it is mac based approach.

Yarn not installing in nvm version node version

I'm running into an issue with yarn when I change my nvm version of node.
I noticed when I check my ~/.nvm folder I see two node versions.
v8.11.0
v8.11.3.
I installed yarn globally. using npm install -g yarn when I was using v8.11.0.
I can see yarn in my
.nvm/versions/node/v8.11.0
But when I switch to nvm v8.11.3 or set my nvm alias default to v8.11.3
Yarn is no longer available. I tried doing a global install again hoping it would add it to my v8.11.3 folder but it keeps trying to add it to v8.11.0
I've even deleted folder v8.11.0 but it just recreates it when I run npm install -g yarn
How can I get it to install so I can use yarn using any node version switch in nvm
When you install a new node version using nvm and then used npm to install yarn, you need to reinstall the yarn for the new node version.
Try:
nvm install 8.11.3
nvm use 8.11.3
npm install -g yarn
This will install yarn in:
.nvm/versions/node/v8.11.3/
You can then switch between 8.11.0 and 8.11.3 and your yarn will still work.
The problem that OP described caused by the fact that globally installed packages lives within their respected namespace (their version), and it cannot be shared across versions. There are a few ways around this. The NON-RECOMMEND WAY is to install yarn via brew, apt or non-node package manager. Although it works, but things may break.
The RECOMMEND WAY is described below.
nvm has a very nice default packages installer. This will installed specified packages when installing a new node version using nvm.
create a text file at $NVM_DIR/default-packages, usually it is located at ~/.nvm/default-packages, with a list of npm packages to be installed.
The content may looks like the following
#vue/cli
create-react-app
firebase-tools
yarn
Documentation link here
try running nvm install --lts to install node's latest lts version, packages specified in the default-packages will be installed automatically.
Check to see if there is a ~/.npmrc file.
If so, delete the content in it.
I recently ran into this issue (on a mac). I had to use
brew install yarn --ignore-dependencies
and that did it for me. Yarn is available no matter what node version I switch to with nvm. Hopefully this helps someone. More information can be found here: https://yarnpkg.com/lang/en/docs/install/#mac-stable
Following the installation guide on official documentation:
If using nvm you can avoid the node installation by doing:
sudo apt update && sudo apt install --no-install-recommends yarn
Note: Due to the use of nodejs instead of node name in some distros, yarn might complain about node not being installed. A workaround for this is to add an alias in your .bashrc file, like so: alias node=nodejs. This will point yarn to whatever version of node you decide to use.
I faced similar issue on mac wherein node v14.20.0 was installed via nvm.
In case of node installation via nvm, it creates symlink target as shown below.
/Users/<user_username>/.nvm/versions/node/v14.20.0/bin/corepack -> ../lib/node_modules/corepack/dist/corepack.js
In such cases, remove existing symlink by executing following coo
rm /Users/<user_username>/.nvm/versions/node/v14.20.0/bin/corepack
Now install yarn via if Node.js <16.10
npm i -g corepack
In case Node.js >=16.10
corepack enable

VS Code terminal fails to use npm version from nvm

I'm using nvm on my Terminal and successfully installed node 10.2.1, which also installed npm 6.1.0. However, when I go to my VS Code editor, it gives me warnings in the integrated terminal for:
npm WARN npm npm does not support Node.js v10.2.1
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4,6, 7, 8, 9.
Turns out, it is actually using npm 5.5.1 (npm -v).
I check to see what's up with that and tried to dig further and eventually used: which npm on both integrated terminal and Mac's CLI.
Mac's Terminal shows:
/Users/Aiz/.nvm/versions/node/v10.2.1/bin/npm
VS Code's Terminal shows:
/usr/local/bin/npm. Which is interesting, because if you do which node in this terminal, it results in the appropriate /Users/Aiz/.nvm/versions/node/v10.2.1/bin/node.
I'm not sure how to get my VS Code terminal to point to the appropriate npm install through nvm. Not sure if it helps, but I checked npm get prefix and npm -g bin to find /Users/Aiz/.nvm/versions/node/v10.2.1. The only difference I'm finding is where each terminal is using npm from.
I ended up looking through VS Code issues on GitHub and came across something relevant to NVM and node issues. It fixed my issue since the underlying cause was the same.
Essentially what happened is that I had a global install of node before that I removed prior to using NVM but hadn't removed my global install of npm. This was causing conflicts in VS Code's terminal (not Mac's terminal). In order to fix this, you essentially have to find the symlink for which npm and remove the node_modules and npm associated recursively.
Here's the link you'll need: https://github.com/Microsoft/vscode-docs/blob/master/docs/editor/integrated-terminal.md#why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched.
Don't forget to restart your editor after.
Another solution is to implement this. https://medium.com/#kinduff/automatic-version-switch-for-nvm-ff9e00ae67f3
Basically, nvm will check for a .nvmrc and switch or default each time you go to a new directory in shell.
It does have a dependency on zsh.
The fix for me on Ubuntu:
A.) sudo apt-get remove nodejs npm
B.) Removed lines in my .bashrc that added the npm package directory to the path.
C.) Restart VS Code.
I doubt step A is necessary. But B and C certainly are.

fish shell and global npm modules

I'm experiencing some issues with my local environment.
I'm using:
homebrew (1.1.4)
fish shell (2.4)
n version manager (2.1.0)
node
npm
All of the above were initially installed via homebrew.
Issues:
Any globally installed modules cannot be run.
I cannot update npm versions.
The node versions I use regularly are 0.10.48 and 6.9.2 - but mostly 4.6.2.
I've created some aliases in fish to be able to get the the global modules to run. I'd prefer to address the root cause rather than continue applying further bandaids though.
Extra info:
~> npm config get prefix
/Users/me/.npm-packages
~> npm bin
/Users/me/node_modules/.bin
What happens when I try to update npm:
~> npm install -g npm#3
/Users/me/.npm-packages/bin/npm -> /Users/me/.npm-packages/lib/node_modules/npm/bin/npm-cli.js
npm#3.10.10 /Users/me/.npm-packages/lib/node_modules/npm
~> npm -v
2.15.9
When I try to call a global module:
~> gulp
fish: Unknown command 'gulp'
What I've tried in order to fix the global modules:
~> cat ~/.config/fish/config.fish
set fish_user_paths /Users/me/.npm-packages
ls ~/.config/fish/functions
bower.fish ember.fish pm2.fish
~> cat ~/.config/fish/functions/bower.fish
function bower
/Users/me/.npm-packages/bin/bower $argv;
end
Any help you can provide will be greatly appreciated! I've been trying to fix this for awhile now without any luck!
You can use installed npm modules. You just need to add npm global path to the shell. To do that, I ran:
$ npm config get prefix
// Output: /usr/local/Cellar/node/9.2.1
and then, added to my fish/config.fish:
set PATH /usr/local/Cellar/node/9.2.1/bin $PATH
This is the Github related link that helped me solving the problem.
What happens when you install node application globally https://docs.npmjs.com/getting-started/fixing-npm-permissions
Configuring in OSX 10.12.5 with
fish v2.6.0
node v8.1.0
example command in terminal returns both
term~> npm install jshint -g
/Users/username/npm-global/lib/node_modules/bin/jshint ->
/Users/username/npm-global/lib/node_modules/jshint/bin/jshint
the PATH you should have in shell to enable you to execute jshint (installed package) -> pointing to the actual install location
Include line below for configuring PATH in file ~/.profile
export PATH="$HOME/npm-global/lib/node-modules/:$PATH"
My permanent solution (with macOS Mojave and fish 2.7.1):
set -U fish_user_paths /Users/{USERNAME}/.npm-packages/bin $fish_user_paths
Btw, below one works but only in terminal session:
set PATH $PATH /Users/{USERNAME}/.npm-packages/bin
Note: You can find npm-packages path with:
printf "%s\n" $PATH
For me non of this worked, so i installed oh my fish nvm plugin
omf install nvm
I resolved this by completely uninstalling (and deleting any traces of) node, npm and n, uninstalling fish shell and changing to zsh instead.
Afterwards, I installed nvm and used it to restore node on my machine.
Global npm modules now work.

Cloud9, use previous version of LESS compiler

I'm trying to downgrade to a previous version of the LESS compiler, an update is causing my program to crash. I can't figure out how to do this... I've done npm install -g less#2.5.2 however when I run lessc -v it returns 2.6.0 again...
How can I change this?
After looking for a while, I finally stumbled upon this: https://docs.c9.io/docs/installing-npm-modules
The global flag does not actually work as I had previously thought it did on Cloud9 (due to their security implementations). The command must be used within the project folder itself.
I needed ones to downgrade lessc to an old version and it did not work for me straight forward
the problem was because npm install differs from sudo npm install
now to fix the problem walkthrough with me, but I not sure if non-linux users can do the same, even though simply sudo is the same as run as administrator
uninstall less using npm uninstall -g less --save
I actually used whereis less to find it, then sudo rm -rf /usr/local/lib/node_modules/less
install the wanted version of less using sudo npm install -g less#1.6.3
check lessc version using lessc -v
hope this helps and
happy maintaining legacy apps