When I install node 0.10.33 from the msi ( http://nodejs.org/download/ ), I get an old version of npm (1.4.28). How can I upgrade npm on Windows?
npm install -g npm
does not work; I still have the old npm.
You need to follow the Windows upgrade instructions ( https://docs.npmjs.com/try-the-latest-stable-version-of-npm )
tl;dr - npm -g install npm does work, but the old version of npm is still in your PATH.
To fix this, do one of these:
Option 2: remove both of
C:\Program Files (x86)\nodejs\npm
C:\Program Files (x86)\nodejs\npm.cmd
Or
Option 3: Open cmd.exe as administrator, navigate to C:\Program Files (x86)\nodejs and
then run the installation without -g:
npm install npm#latest
*There is an npm package that automate this Option 3:
npm install -g npm-win-upgrade
We at Microsoft Open Source wrote a small tool to automate the process outlined above. You can find it here or just install and run it by executing the following in an elevated command prompt / PowerShell:
npm install -g npm-windows-upgrade
npm-windows-upgrade
There May be many ways to update your npm in Windows
Way 1
Open you power shell as Administrator and run following commands step by step.
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
Here you can select your preferred version of npm
Ready to go !
Way 2
You can simply upgrade to the latest npm version with following command
npm install npm#latest -g
or if you want a specific version of npm simply run
npm install npm#{version} -g for example npm install npm#3.3.12 -g
Now simply run npm --version or npm -v to know your current version of npm
3.3.12 is my preferred version of npm that best suits for approximately every package.
UPDATE
npm install npm#latest -g
the correct npm version is now already shipped with node.js so you can directly switch node version.
you can nvm (Node Version Manager) package to switch node versions very quick and easy.
So, TL;DR; this worked:
Uninstall node
From a command prompt, run where npm
If you had npm installed via chocolatey, you'll see a path like C:\ProgramData\chocolatey\bin\npm.exe - DELETE it!
Now install NodeJS using the appropriate MSI from https://nodejs.org/en/download/
In your favourite shell, type npm --version - this should now echo the version of NPM that came with NodeJS (at the time of this writing, that version is 3.10.10)
This is what worked for me (goofy me!)
I had (age ago) installed npm via chocolatey, which created a chocolatey initiated npm.exe in C:\ProgramData\chocolatey\bin\npm.exe. This was npm version 1.4.9 and wouldn't update no matter what one did including uninstall and reinstall NodeJs.
=======
EDIT: Better way to install node and npm
As of today (27/06/2017), the best way to install and manage node and npm is to install nvm (Node Version Manager) as explained here: https://github.com/coreybutler/nvm-windows. Once you have nvm, installing any node version is super easy:
Open your favourite console (CMD, Cmder, PowerShell)
Type nvm install 6.10.2 (to install node version 6.10.2)
To see the currently active version, type nvm list. This prints something like below:
6.9.3
* 6.9.2 (Currently using 64-bit executable)
6.9.1
6.10.2
It's late 2021 and a lot of these answers can be confusing. npm install -g npm can break your installation. (When I did this, I had to run the Node MSI "Repair" tool to get it working again.) npm-windows-upgrade has not seen a release in over 2 years, and the repo has been archived by its maintainer.
As far as I can tell, there are two options that seem to work reliably today.
Use where npm from DOS prompt or which npm from WSL / Git Bash / etc, to determine which NPM binary is being used.
cd to that path, then run npm install npm#latest (without the -g flag!). npm update npm should have the same effect. You may need an elevated prompt (Run As Administrator).
Verify that this worked by running npm --version.
This worked for me. The other option is:
Completely uninstall NPM + Node using the Add/Remove Programs settings page.
Install an MSI from the Node website.
To upgrade NPM on windows 10
Uninstall Node.js
Restart your system
on command prompt type where npm
delete if npm and npm-cache folder exists in AppData/Roaming
Install Node.js (https://nodejs.org/en/)
You need to follow the Windows upgrade instructions
https://www.npmjs.com/package/npm-windows-upgrade
First, ensure that you can execute scripts on your system by running the following command from an elevated PowerShell. To run PowerShell as Administrator, click Start, search for PowerShell, right-click PowerShell and select Run as Administrator.
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install --global --production npm-windows-upgrade
npm-windows-upgrade
Want to just install the latest version?
1.npm-windows-upgrade --npm-version latest
I did something similar to Sam Mikes. I'm only sharing this because I couldn't get either of his solutions to work on my rig. After a bit of playing around, this is what worked for me:
Remove NPM/Node from your Environment Variables, both for user and system.
Close your open console if you have one open, then open a console as administrator
Change directories to %USERPROFILE% -- that's a window's environment variable that takes you to C:\Users\CurrentlyLoggedInUser
Run from the console in %USERPROFILE%, "C:\Program Files\nodejs\npm" install npm -g (you might have yours in the x86 folder)
If this solution would work for you, step 4 would have worked, and npm -v will show a an up-to-date version
Re-add Node (in Program Files)/NPM (in App Data -- the one installed in Program Files should be the old one) to your user and system environment variables
Note: I've used the Microsoft automated script in the past to fix this, but only because I didn't realize how easy it would be to do it myself.
So none of the previous answers solved the issue for me so I thought I would post my specific solution, which I managed to figure out by going through all the other answers so they were really helpful.
My issue was because I had used chocolatey to install node and possibly npm (looking at chocolatey site now I shouldn't have done that).
To solve the issue I simply had to run the relevant choco uninstall commands for npm and node and then everything switched to the other version of node which I had also installed using the node msi (from node's website).
I hope that helps anyone else that may have gone down the same path as me.
I tried almost every answer but none of them works my way.
Neither npm-windows-upgrade worked nor did the npm install npm#latest etc etc worked.
For people like me I will suggest you guys downloading the latest installer from Node.js website, let the existing version of node directory be on it's place and without changing anything just install the msi installer and you will end up with an upgraded version of node.
My case was upgrading node from 6 to 8.9.3
all npm install commands were getting stuck and will throw error (behind proxy error) after sometime. setting up proxy was not helping. This is what I did.
Had 8.11 nodeJS
Uninstalled NodeJS from Programs & Features with the uninstaller.
Reboot (or you probably can get away with killing all node-related processes from Task Manager).
Look for these folders and remove them (and their contents) if any still exist. Depending on the version you installed, UAC settings, and CPU architecture, these may or may not exist:
• C:\Program Files (x86)\Nodejs
• C:\Program Files\Nodejs
• C:\Users{User}\AppData\Roaming\npm (or %appdata%\npm)
• C:\Users{User}\AppData\Roaming\npm-cache (or %appdata%\npm-cache)
• C:\Users{User}.npmrc (and possibly check for that without the . prefix too)
Check your %PATH% environment variable to ensure no references to Nodejs or npm exist.
If it's still not uninstalled, type where node at the command prompt and you'll see where it resides -- delete that (and probably the parent directory) too.
Reboot, for good measure.
Installed 6.11 nodejs then it worked.
Use npm-windows-upgrade tool to simply upgrade. Steps are provided in the link.
For update node npm on Windows
I have to delete node in:
C:\Users**YOUR USER**\AppData\Roaming
And reinstall node
Related
Running windows 7 Professional 32bit.
I tried running npm install -g angular-cli both under normal or admin.
I also tried adding it to the Enviorment Variables under PATH: (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng) , with no success also.
What am i doing wrong?
I solved this problem in accordance with the figure:
run in cmd
npm install -g #angular/cli
and then
( open in Windows 10) Control Panel\All Control Panel Items\System
or accordance with the figure
step 1:
step 2 :
step3:
step4:
step5: add missing ng path
Here is new environment variable that you need add: C:\Users\PK\AppData\Roaming\npm\node_modules\#angular\cli\bin
Finally, restart all opened command prompts and try again.
For me it works with:
npm run ng <command>
Adding C:\Users\DELL\AppData\Roaming\npm to System Variable Path worked for me. Please find your appropriate file path to 'npm'
Also, check if you have added your angular-cli\bin path to the path variable.
I am using WIN 10, just figure it out for this problem.
Type the code below in cmd:
npm config get prefix
and copy&paste the path that you get it from the top into your computer environment variables-->user variables box --> path --> edit -- C:\Program Files\nodejs\node_global, your path may different.
Click Ok and reopen your cmd window, type in ng version, then it works! Cheers!
Just open your command prompt (run as administrator). Ensure node --v is 6.9.0 or higher and npm --v is 3.0.0 r higher.
After that run the following command:
npm install -g #angular/cli
Once angular is installed. you can see an entry of angular cli in the path
C:\Users\Dell\AppData\Roaming\npm\node_modules\#angular
Then try ng help. It will work.
1) Enter below command on command prompt
npm install -g #angular/cli
2) Make sure that C:\Users\_username_\AppData\Roaming\npm this path is not hidden.
3) Add C:\Users\_username_\AppData\Roaming\npm and
C:\Users\_username_\AppData\Roaming\npm \node_modules#angular\cli\bin to both enviroment variable path.
4) Open new command prompt and type ng help. It will work.
With a command
npm install -g #angular/cli#latest
It works fine, I am able to run ng command now.
I solved it few days ago, after having the same problem with other global modules, by adding to:
Environment Tables -> System variables -> Path:
C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin;C:\Program Files\MongoDB\Server\3.2\bin
Note that it must not have any spaces after ;
That turned out to be my problem.
I followed below steps for resolution for this issue in Windows 10:
First make sure you have installed Angular CLI . You can use below
to install same.
npm install -g #angular/cli#latest
Make sure that AppData is visible and navigate to path below.
C:\Users\rkota\AppData\Roaming\npm
Same path can be found by running below too:
npm config get prefix
Add the above path i.e. " C:\Users\rkota\AppData\Roaming\npm" in Environment variable PATH and make sure it got added by running path in command prompt.
Close command prompt and now try to run below:
ng --version
you will be able to see CLI version.
execute following lines in order to solve the issue for both not found and undefined version of ng
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
npm cache clean
npm install -g #angular/cli#latest
Instead of using the in-built command prompt better start using the NodeJS installed version of command prompt. Then it is going to work perfectly without any issues.
General problem is that OS tries to find the PATH variable with ng keyword and cannot find it.
For me, even after the steps #behrouzmoslem suggested in the top answers to this post I didn't manage to get it work, because after the launch of ng command OS started to respond, but opens up editor file by the path C:\Users\{username}\AppData\Roaming\npm\node_modules\#angular\cli\bin\ng which is actually funny. So, solution is:
Just use npx before any angular executables.
Eg : npx ng serve for serving the angular app or npx ng build --watch to build with watcher.
If you get the error even after following the above step. then try below.
Since it is a node script. I am using the below option to create as of now.
node C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng version
May be symbolic links are required. Not researched further.
On Further Research:
Set Path as : %PATH%;C:\Users\Administrator\AppData\Roaming\npm;
In Windows, npm.cmd file is in the above path. If the above Environment variable is set, you can execute as
ng version
ng init
Open cmd and type npm install -g #angular/cli
In environment variables, add either in the user variable or System variable "Path" value=C:\Users\your-user\.npm-packages\node_modules\.bin
In cmd: c:\>cd your-new-project-path
...\project-path\> ng new my-app
or ng all-ng-commands
I resolved by adding - %AppData%\npm\node_modules#angular\cli\bin\ path to my environment variables path
close cmd and open it again with admin right or reboot ur system.
for me it works only with the flag --force:
npm install -g #angular/cli --force
If everything is fine then you shoud see the folder node_modules in this path:
C:\Users\YOUR_USERNAME\AppData\Roaming\npm\
I faced same issue when i tried to install angular cli locally with command
npm install #angular/cli#latest
After that i got same issue
C:\Users\vi1kumar\Desktop\tus\ANGULAR\AngularForms>ng -v
'ng' is not recognized as an internal or external command,
operable program or batch file
Than i tried to install it globally
npm install -g #angular/cli#latest
In this case it worked I was wondering that is it not possible to install cli globally ?
After doing some research I found this article very helpful hope it will help someone facing similar issue
Working with multiple versions of Angular CLI
This one almost worked for me, but I had to use: %USERPROFILE%\AppData\Roaming\npm
. In Environment Variables.../System variables/Path
Then when I did CMD: "ng -v" I got the correct response for angular cli.
npm install -g #angular/cli helped for me instead of npm install #angular/cli
1- Install
$ npm install -g #angular/cli
2- Make sure where your ng.cmd is present.
3- Then add this path into variables.
I had the same problem on Windows 7, 64 bits running with npm v3.10.8.
I added the path as it was suggested: ( C:\Users.....(your user name)\AppData\Roaming\npm\node_modules\angular-cli\bin\ng) and uninstalled angular-cli.
After this, I cleared the npm cache by npm cache clean as prompted here https://blogs.msdn.microsoft.com/matt-harrington/2012/02/23/how-to-fix-node-js-npm-permission-problems/. This guarantees there are no leftovers.
Reinstalled angular-cli with npm install -g angular-cliand voila.
Hope that may be useful!
In my case I did below steps.
All Programs -> Node JS-> Right click on Node.js Command Prompt and select properties and from Target string at end copy below
/k "C:\Program Files\nodejs\nodevars.bat"
I launched Visual Studio Code and opened below file
C:\Users\gochinta\AppData\Roaming\Code\User\settings.json and gave below
// Place your settings in this file to overwrite the default settings
{
"terminal.integrated.shellArgs.windows":
["/k", "C:\\Program Files\\nodejs\\nodevars.bat"]
}
Now I typed ng -v in my Visual Studio Code Terminal window and it worked.
I was having the same issue when tried with the syntax "ng new " and solved that simply by updating the existing node version from 5.x.x to 8.x.x. After successful updation of node, the syntax worked perfectly for me. Please update the existing version of node. As it is clearly mentioned in angular documentation that these commands require the node version >= 6.9.x. For reference please check https://angular.io/guide/quickstart. It clearly states "Verify that you are running at least node 6.9.x and npm 3.x.x by running node -v and npm -v in a terminal/console window. Older versions produce errors, but newer versions are fine".
I faced same issue on x86, windows 7;
uninstalled #angular/cli
re-installed #angular/cli
checked & verified environmental variables (no problems there)...
Still same issue:
Solution was the .npmrc file at C:\Users{USERNAME}... change the prefix so that it reads "prefix=${APPDATA}\npm"... Thanks to this website for help in resolving it
For me something was wrong in the PATH enviroment variable. I removed all path related to npm and added at the start of PATH this folder:
c:\Users\<your-user-name>\AppData\Roaming\npm\
Make sure you have ; between paths.
I am facing same issue and it's get resolved. At my end reason is i install node and CLI using other user profile and now i am running ng command from other user login. Since node and cli installed using other user login node is not finding anything on C:\Users\<user name>\AppData\Roaming this path and that's why i am getting this error.
I run npm install -g #angular/cli command and restart my machine. Every thing is working fine.
Sometime in the future. Applicable to Windows 8.1 machine.
Run the following commands
npm install -g #angular/cli
Log out or restart your machine.
This should add the required env path, rather than doing it manually.
I also tried to play with cmd by setting environment variable path & etc, but simple answer is use nodejs command prompt.
So you no need to set environment variable path or anything. When you insalled nodejs it will give it's command prompt, by using that you us "ng" command, without any settings.
Since this question is still asked over and over again one year later I will post my answer here as well.
The clue (on Windows only) is to arrange the entries in the path variable right.
As the NPM wiki tells us:
Because the installer puts C:\Program Files (x86)\nodejs before C:\Users\\AppData\Roaming\npm on your PATH, it will always use version of npm installed with node instead of the version of npm you installed using npm -g install npm#<version>.
So your path variable will look something like:
…;C:\<path-to-node-installation>;%appdata%\npm;…
Now you have two possibilities:
Swap the two entries so it will look like
…;%appdata%\npm;C:\<path-to-node-installation>;…
This will load the npm version installed with npm (and not with node) and with the installed Angular CLI version.
If you (for whatever reason) like to use the npm version bundled with node, add the direct path to your global Angualr CLI version. After this your path variable should look like this: …;C:\Users\<username>\AppData\Roaming\npm\node_modules\#angular\cli;C:\<path-to-node-installation>;%appdata%\npm;…
or …;%appdata%\npm\node_modules\#angular\cli;C:\<path-to-node-installation>;%appdata%\npm;…
for the short form.
This worked for me since a while now.
I have manually installed "node.exe" (0.10.36 x64) & NPM Zip (1.4.12) under Windows 7.
When I run a NPM command (from cmd, powershell or Eclipse TCF terminals), it prints a lot of a new line with single character from this list: -\|/.
However, it doesn't with Eclipse console.
It uselessly fills the console and makes difficult to see messages, especially when running some infinite running command like "karma start".
Is there any way to remove/fix these ugly output characters ?
It's an issue of "1.4.12" and "1.4.13" versions. Switch back to 1.4.10 (1.4.11 doesn't work at all on my computer) has solved the issue.
Another solution can be to upgrade to newer versions of npm simply running npm install npm --global. If want to easy switch NPM versions, just copy "npm.cmd" and "node_modules/npm" to another directory. Then from this directory, run npm install npm. Finally, update your PATH to take this directory in priority (or remove the old npm versions).
I have the same issue on Win 10. I was previously using v0.12.7 (I did not know why I used a so "old" version) then installed v4.2.2 which makes ugly output.
To solve this problem, I uninstalled v4.2.2 from Control Panel, removed npm and npm_cache folder from %APPDATA%, and finally removed all paths related to Node and npm from PATH environment variable.
Hope this could help someone.
This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
I tried this:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
...but it didn't work.
How do I do this on Windows?
Note: The question is specifically asking how to upgrade npm, not Node.js. If you want to update Node.js over a CLI on windows, I recommend running winget upgrade -q NodeJS or use chocolatey for that.
What method should I choose to update NPM?
Node.js v16 or higher?
npm install -g npm
Node.js v14 or below?
Consider updating to latest LTS release of Node.js
npm-windows-upgrade
Upgrade with npm-windows-upgrade
Run PowerShell as Administrator
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
Note: if you run the Node.js installer, it will replace the Node.js version.
Upgrades npm in-place, where Node.js installed it.
Does not modify the default path.
Does not change the default global package location.
Allows easy upgrades and downgrades and to install a specific version.
A list of versions matched between NPM and Node.js (https://nodejs.org/en/download/releases/) - but you will need to download the Node.js installer and run that to update Node.js (https://nodejs.org/en/)
Upgrade with npm
npm install -g npm
Note: some users still report issues updating npm with npm, but I haven't had that experience with v16+.
Download and run the latest MSI. The MSI will update your installed node and npm.
To update NPM, this worked for me:
Navigate in your shell to your node installation directory, eg C:\Program Files (x86)\nodejs
run npm install npm (no -g option)
Like some people, I needed to combine multiple answers, and I also needed to set a proxy.
This should work for anyone. I have zero desire to run an EXE file or MSI file .. uninstall/ reinstall, or manually delete files and folders. That is so 1999 :P
Run this to update NPM:
Run PowerShell as administrator
npm i -g npm // This works
I am not thinking this code actually upgrades your npm version below
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
(courtesy of "Robert" answer)
Run this to update Node.js:
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files (x86)\nodejs\node.exe' (courtesy of BrunoLM answer)
If you get `wget : Could not find a part of the path .... "**, see below ...scroll down. Reading Web Response... It's at least punching through the firewall /proxy (if you have one or have already ran the code get through ...
Otherwise
You might need to set your proxy
npm config set proxy "http://proxy.yourcorp.com:811" (yes, use quotes)
2 possible errors
It cannot find path of the path solution "where.exe node" (courtesy of Lonnie Best Answer)
E.g. if Node.js is NOT living in "Program Files (x86)" perhaps with where.exe, it is living in 'C:\Program Files\nodejs\node.exe'.
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
Now perhaps it tries to upgrade but you get another error, "node.exe is being used by another process."
Close /shutdown other consoles .. command prompts and PowerShell windows, etc. Even if you're using npm in a command prompt, close it.
npm -v (3.10.8)
node -v ( v6.6.0)
DONE. I'm at the version that I want.
You can update your npm to the latest stable version with the following command:
npm install npm#latest -g
Use PowerShell to run it. This command doesn't need windows administrator privileges and you can verify the result with npm -v
You can use Chocolatey which is a package manager for windows (like apt-get for Debian Linux).
Install fresh (you might need to uninstall previously installed versions)
> choco install nodejs
Update to the latest version
> choco update nodejs
and for npm
> choco update npm
The previous answers will work installing a new version of Node.js (probably the best option), but if you have a dependency on a specific Node.js version then the following will work: "npm install npm -g". Verify by running npm -v before and after the command.
This works fine for me to update npm on Windows 7 x64:
Windows start
All Programs
Node.js
Node.js command prompt (alternative click)
Run as administrator
$ npm -g install npm
remove C:\Program Files\nodejs\npm.cmd the new npm will be at C:\Users\username\appdata\roaming\npm\npm.cmd
Hope this helps.
Open PowerShell as administrator.
To install a first time you can use this small script to download the latest msi and run it
$nodeLatest=((curl https://nodejs.org/download/release/latest/).Content | findstr x64.msi) -replace "<(.*?)>", "" -replace "\s+.+", "";
wget "https://nodejs.org/download/release/latest/$nodeLatest" -OutFile (join-path $env:TEMP node.msi); Start-Process (join-path $env:TEMP node.msi)
On future upgrades you can download just node.exe and update npm with
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
npm i -g npm
You should now have the latest node and npm.
I went a little further and decided to implement a nvm for Windows.
https://github.com/brunolm/nvm
Install-Module -Name power-nvm
nvm install latest
nvm default latest
1. Installing latest npm version
npm install –g npm#latest
(You can type "npm –version" to check that)
2. Installing Node
a. Install node new version via following URL: https://nodejs.org/en/download/current/
Follow the default choices
b. Remove C:\Users\\AppData\Roaming\NPM
c. Remove C:\Users\\AppData\Roaming\npm-cache
Optionally:
d. (Delete node_modules folder in your current project folder)
e. npm cache verify
f. npm install
Use Upgrade npm on Windows
This is the official document for a user to upgrade npm on Windows!
Here is my screenshot!
For what it's worth, I had to combine several answers...
Uninstall Node.js in control panel Add/remove programs.
Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.
Install the latest version, http://nodejs.org/download/
How to Update Node.js:
Uninstall Node.js. Click the Start menu, type "Change or Remove a Program", click on the item shown, find Node.js in the list and uninstall it.
Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.
Install the latest, https://nodejs.org/en/download
The uninstall/delete/install seems unnecessary, but it often is and this will save your time.
These instructions come from Microsoft.
How to Update NPM:
https://www.npmjs.com/package/npm-windows-upgrade
This is the official documentation for upgrading npm on windows.
All was tested and working on Windows 10 (2017).
this is best tool to maintain version of NODE.Js i NVM
Node Version Manager (nvm) for Windows
but for Windows, with an installer. Download Now! This has always been a node version manager, not an io.js manager, so there is no back-support for io.js. However, node 4+ is supported.
For me, after totally uninstalling node 10.29, and then installing node 4.2.2, there remained a 10.29 node.exe file in my c:\windows folder.
I found this by using the following command:
where.exe node
The command returned:
C:\Windows\node.exe
C:\Program Files\nodejs\node.exe
So even though I had successfully installed version 4.2.2 via the msi executable, the command node -v would continue to report I was running version 10.29.
I resolved the problem by deleting this file:
C:\Windows\node.exe
Thereafter, node -v reported the upgraded version instead of the unwanted remnants of the prior version.
For NodeJS
Download required node version msi from here and install
for Npm
Run PowerShell as Administrator
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
This works fine for me
Run Command Prompt as Administrator
Navigate to the folder containing nodejs (eg. C:\Program Files\nodejs)
Run Powershell -ExecutionPolicy Unrestricted
Run npm-windows-upgrade
This will show list of versions available to install. Just select your desired version by moving up/down key & Press Enter.
This'll update your npm
To check the current version of npm
Run npm --version
Command Prompt Screenshot
I was also facing similar issues. I followed below mentioned steps and it worked for me:
go to Windows > Start > Node.js
right click on Node.js command prompt
click on Run as administrator
ping registry.npmjs.org
npm view npm version
cd %ProgramFiles%\nodejs
npm install npm#latest
and npm updated successfully. Earlier I was trying for CMD and that was throwing error. may be some path issue that got resolved by running NodeJs Command Prompt. hope it'll work for you. try this.
OK guys, I read (tried on Windows) all the previous stuff and all of these answers have their own disadvantages.
For the best way to update Node.js (at least for me), go to https://nodejs.org/en/
Then download the last version and install it in same folder you installed the previous version in - 1 min and it's done. You don't need to remove any old files.
Then update npm typing in cmd: npm install --save latest-version
To install the updates, just download the installer from the Nodejs.org site and run it again. The new version of Node.js and NPM will replace the older versions.
The easiest way I found so far to update Node.js is using Chocolatey.
Use Chocolatey to install or update the latest version of Node.js on Windows:
Step 1: First, ensure that you already have Chocolatey installed. If not, use an administrative shell to install chocolatey through cmd.exe or PowerShell.exe. For more information, visit: https://chocolatey.org/docs/installation
Step 2: Install with cmd.exe. Run the following command:
#"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
To install with PowerShell.exe, visit: https://chocolatey.org/docs/installation
Step 3: Install or Update with following commands on cmd.exe (on administrative mode)
To Install Node.js: cinst nodejs.install
To Update Node.js: cup nodejs.install
follow these steps for window 10 or window 8
press WIN + R and type cmd and enter
npm i -g npm#next
npm i -g npm#next OR npm i -g node#{version}
Remove environment path C:\Program Files\nodejs from envrionment variable PATH.
type refreshenv in cmd
Now you will have your new version which you installed.
Note: If you don't remove path. You will see the previous version of node.
PowerShell does not execute npm directly, so I suggest using
.\npm install -g npm-windows-upgrade
.\npm-windows-upgrade
And it failed with:
You wanted to install npm 6.1.0, but the installed version is 3.10.10.
A common reason is an attempted "npm install npm" or "npm upgrade npm". As of today, the only solution is to completely uninstall and then reinstall Node.js. For a small tutorial, please see http://aka.ms/fix-npm-upgrade (dead link).
Please consider reporting your trouble to npm-windows-upgrade.
I followed josh3737 and installed the latest MSI from the Node.js homepage.
But I had the additional problem that I still had the old version of Node.js and npm on the command line. The problem was caused by the new installation, and that it was installed into
C:\Program Files (x86)\nodejs\
instead of the previous installation in
C:\Program Files\nodejs\
The new installation added the new directory into my path variable after the old one. So the old installation was still the active one in the path. After removing C:\Program Files\nodejs\ from system path and C:\Users\...\AppData\Roaming\npm from user path and restarting the command line the new installation was active.
Maybe the least path was a local problem that has nothing to do with the new installation. I had two links to AppData\Roaming\npm in it. And maybe this can also be fixed by first uninstalling Node.js and installing the new version afterwards.
You can use these commands:
npm cache clean
npm update -g [package....]
If you are upgrading from a previous version of node, then you will want to update all existing global packages.
You can also specify the package name to be updated.
This might help someone. Neither "npm-windows-upgrade" nor the installer alone did it for me. Powershell was still using an older version of node and npm.
So this is what I did (worked for me):
1. Download the latest installer from nodejs.org. Install node. It will update your node; everywhere (Powershell, cmd etc.).
2. Install the npm-windows-upgrade package (npm install -g npm-windows-upgrade) and run npm-windows-upgrade.
I didn't uninstall anything and didn't set any paths.
In my case, I discovered that I had two copies of Node.js installed. One under "C:\Program Files\nodejs" and another under "C:\Program Files (x86)\nodejs".
This is what worked for me.
Open a local folder other than the one in which nodejs is installed.
Install npm in that folder with command npm install npm
Navigate to the folder containing node js. (C:\Program Files\nodejs\node_modules)
Delete the npm folder and replace it with the npm and bin folders in the local folder.
Run npm -v. Now you would get updated version for npm.
Note: I tried installing npm directly in "C:\Program Files\nodejs\node_modules" but it created errors.
Start
Search for windows powershell
Right click and run as administrator
Type: where.exe node (returns the path of node.exe in your system. Copy this)
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'PATH-OF-NODE.EXE_WHICH_YOU_COPIED_JUST_NOW'
To check if it has worked, go to your Git bash/Normal command prompt and type: node -v
Here you can find the current version of node: https://nodejs.org/en/blog/release/
I am being more cautious than usual because I have been confused by the behavior of npm in the past.
I am on a Mac and have installed node.js through brew install node.
Now that I want to run jslint.js on the command-line as the command jslint I find that the canonical way to accomplish this is sudo npm install -g jslint which ran successfully with this output:
$ sudo npm install -g jslint
npm http GET https://registry.npmjs.org/jslint
npm http 200 https://registry.npmjs.org/jslint
npm http GET https://registry.npmjs.org/jslint/-/jslint-0.1.9.tgz
npm http 200 https://registry.npmjs.org/jslint/-/jslint-0.1.9.tgz
npm http GET https://registry.npmjs.org/nopt
npm http 200 https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz
npm http 200 https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz
npm http GET https://registry.npmjs.org/abbrev
npm http 200 https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/abbrev/-/abbrev-l.0.4.tgz
npm http 200 https://registry.npmjs.org/abbrev/-/abbrev-1.0.4.tgz
/usr/local/share/npm/bin/jslint -> /usr/local/share/npm/lib/node_modules/jslint/
bin/jslint.js
jslint#0.1.9 /usr/local/share/npm/lib/node_modules/jslint
└── nopt#1.0.10 (abbrev#1.0.4)
Subsequently
$ jslint ply.js
zsh: command not found: jslint
due to /usr/local/share/npm/bin not being in my $PATH.
1) Why did brew not install global npm bin path to path? Maybe it did, but something zsh does is messing it up. Where might I be able to find that?
2) Should I do this? (Append :/usr/local/share/npm/bin to the exported $PATH at the bottom of my ~/.zshrc)
It seems like this isn't the right way to do it because if I install something else later (using Homebrew or something) I'll be needing to append it to my zsh startup script to set the path. I guess in this particular instance it's just a matter of the npm install -g not making the right symlinks in a "proper" location (like /usr/local/bin maybe).
I think what I will do is manually build out symlinks inside /usr/local/bin for any programs that I have trouble with and it should be good enough for my purposes.
EDIT: I'm updating this in 2019, because this old question is popular but now outdated both in terms of my personal workflow and also in terms of how to best go about installing node and managing its various dependencies.
My personal workflow is now to use the installer obtained from nodejs.org to install node on systems. I actually trust this more than the homebrew package itself, because it knows best how to manage the files. If you want to change your system node from 8.10 to 10.15, whether on Mac or Windows, simply download the installer from nodejs.org for 10.15 for your OS. Attempting to upgrade node installed via homebrew has always proven to be a more difficult approach in my experience.
Also, the biggest thing to point out is that the use of sudo as shown in my npm install of jslint example above is highly discouraged; I am fairly certain that homebrew packages should never be installed or interacted with in any way using the superuser. It should not be necessary, and will lead to file permission headaches!
Furthermore I recommend ESLint over jslint, and have not used jslint in years.
Extending your PATH with:
export PATH=/usr/local/share/npm/bin:$PATH
isn't a terrible idea. Having said that, you shouldn't have to do it.
Run this:
npm config get prefix
The default on OS X is /usr/local, which means that npm will symlink binaries into /usr/local/bin, which should already be on your PATH (especially if you're using Homebrew).
So:
npm config set prefix /usr/local if it's something else, and
Don't use sudo with npm! According to the jslint docs, you should just be able to npm install it.
If you installed npm as sudo (sudo brew install), try reinstalling it with plain ol' brew install. Homebrew is supposed to help keep you sudo-free.
Spent a while on this issue, and the PATH switch wasn't helping. My problem was the Homebrew/node/npm bug found here - https://github.com/npm/npm/issues/3794
If you've already installed node using Homebrew, try ****Note per comments that this might not be safe. It worked for me but could have unintended consequences. It also appears that latest version of Homebrew properly installs npm. So likely I would try brew update, brew doctor, brew upgrade node etc before trying****:
npm update -gf
Or, if you want to install node with Homebrew and have npm work, use:
brew install node --without-npm
curl -L https://npmjs.org/install.sh | sh
I use brew and the prefix was already set to be:
$ npm config get prefix
/Users/[user]/.node
I did notice that the bin and lib folder were owned by root, which prevented the usual non sudo install, so I re-owned them to the user
$ cd /Users/[user]/.node
$ chown -R [user]:[group] lib
$ chown -R [user]:[group] bin
Then I just added the path to my .bash_profile which is located at /Users/[user]
PATH=$PATH:~/.node/bin
I managed to fix Vue Cli no command error by doing the following:
In terminal sudo nano ~/.bash_profile to edit your bash profile.
Add export PATH=$PATH:/Users/[your username]/.npm-packages/bin
Save file and restart terminal
Now you should be able to use vue create my-project and vue --version etc.
I did this after I installed the latest Vue Cli from https://cli.vuejs.org/
I generally use yarn, but I installed this globally with npm npm install -g #vue/cli. You can use yarn too if you'd like yarn global add #vue/cli
Note: you may have to uninstall it first globally if you already have it installed: npm uninstall -g vue-cli
Hope this helps!
brew should not require you to use sudo even when running npm with -g. This might actually create more problems down the road.
Typically, brew or port let you update you path so it doesn't risk messing up your .zshrc, .bashrc, .cshrc, or whatever flavor of shell you use.
In newer MacOS versions you need to edit the .zshrc file not .bash_profile:
In your terminal nano ~/.zshrc
then add the line:
export PATH=$PATH:/Users/[your username]/.npm-packages/bin
Try running:
PATH=$PATH:~/npm/bin
and then do a test by running express in the command line. This worked for me.
If you have linked the node packages using sudo command
Then go to the folder where node_modules are installed globally.
On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally. If you set the NODE_PATH environment variable to this path, the modules can be found by node.
Windows XP - %USERPROFILE%\Application Data\npm\node_modules
Windows 7 - %AppData%\npm\node_modules
and then run the command
ls -l
This will give the list of all global node_modules and you can easily see the linked node modules.
sudo brew is no longer an option so if you install with brew at this point you're going to get 2 really obnoxious things:
A: it likes to install into /usr/local/opts or according to this, /usr/local/shared. This isn't a big deal at first but i've had issues with node PATH especially when I installed lint.
B: you're kind of stuck with sudo commands until you either uninstall and install it this way or you can get the stack from Bitnami
I recommend this method over the stack option because it's ready to go if you have multiple projects. If you go with the premade MEAN stack you'll have to set up virtual hosts in httpd.conf (more of a pain in this stack than XAMPP)plust the usual update your extra/vhosts.conf and /etc/hosts for every additional project, unless you want to repoint and restart your server when you get done updatading things.
Any one got the same issue it's related to a conflict between brew and npm
Please check this solution https://gist.github.com/DanHerbert/9520689
I uninstalled node from homebrew on M1 Apple Silicon and instead used the Mac Installer from https://nodejs.org/en/download/. After doing that I was able to install with npm and npx.
Simple solution is ...
Just put below command :
sudo npm config get prefix
if it's not something like these /usr/local, than you need to fix it using below command.
sudo npm config set prefix /usr/local...
Now it's 100% working fine
just installed new ubuntu vm to test around with node
installed things in this order:
node
mongodb-server
npm
express
mongoose
now, trying to create a new app i noticed express cannot be used in the shell.
express -v returns
express: command not found
i installed npm like this
curl http://npmjs.org/install.sh | sudo sh
and i installed express this way
npm install express
any ideas?
Starting from express 4.00 you also need to install express generator with:
npm install -g express-generator
Only after this will you be able to run express as a command!
For confirmation see: ExpressJS.com - Migrating to Express 4
npm install express -g
You need to install it globally.
Npm 1.0 installs modules locally by default. So the bash executable lives in /node_modules/bin/. You can add that folder to PATH or you can just install express globally so that it's picked up by PATH
I had this problem and was installing node via Homebrew. The problem was being caused by Homebrew.
So I did:
brew uninstall node
and then installed node using the installer on the nodejs.org site.
Then I ran:
npm install -g express
And voila no problems.
With the release of Express 4.0.0 it looks like you need to do sudo npm install -g express-generator.
EDIT 2017-06-29: this answer is 6+ years old, but still gets votes/traffic. Instead (for any new users with problems) I'd trust both NODE_PATH official doc and its corresponding bit about REPL usage before this answer.
Quite similar to this issue, node was not finding my global express install, so a require('express') statement would fail.
What fixed this for me, when a global install wasn't being picked up by node was making sure NODE_PATH env. variable was is set correctly.
On Ubuntu 11.04, with node version 0.5.0-pre, the paths me were:
NODE_PATH=/usr/local/lib/node_modules:/usr/local/lib/node
So, to clarify you might want to export the above env. variable, or you can just test the above values out by doing:
NODE_PATH=/usr/local/lib/node_modules:/usr/local/lib/node node ./you_app.js
I had to do a combination of things:
From node.js modules path:
echo 'export NODE_PATH="'$(npm root -g)'"' >> ~/.bash_profile && . ~/.bash_profile
This sets the file path in bash profile (can be viewed using nano .bash_profile
Slightly modified from Raynos (above) since I needed sudo:
sudo npm install express -g
Slightly modified from Fazi (above) since I needed sudo:
sudo npm install -g express-generator
TEST YOUR APPLICATION:
run `DEBUG=myapp:* npm start`
Ref: http://expressjs.com/en/starter/generator.html
IF you are running windows:
export NODE_PATH="C:\Users\IMarek\AppData\Roaming\npm\node_modules"