Nice programing

Windows에서 npm을 어떻게 업데이트합니까?

nicepro 2020. 10. 6. 19:05
반응형

Windows에서 npm을 어떻게 업데이트합니까?


msi ( http://nodejs.org/download/ ) 에서 노드 0.10.33을 설치 하면 이전 버전의 npm (1.4.28)을 얻습니다. Windows에서 npm을 어떻게 업그레이드 할 수 있습니까?

npm install -g npm

작동하지 않습니다. 나는 여전히 오래된 npm을 가지고 있습니다.


Windows 업그레이드 지침 ( https://docs.npmjs.com/try-the-latest-stable-version-of-npm ) 을 따라야합니다.

TL; DR은 - npm -g install npm 않는 일을하지만, NPM의 이전 버전은 PATH에 아직도있다.

이 문제를 해결하려면 다음 중 하나를 수행하십시오.

옵션 2 : 둘 다 제거

C:\Program Files (x86)\nodejs\npm

C:\Program Files (x86)\nodejs\npm.cmd

또는

옵션 3 : 관리자 권한으로 cmd.exe를 열고 C : \ Program Files (x86) \ nodejs로 이동 한 다음 -g없이 설치를 실행합니다.

npm install npm@latest

*이 옵션 3을 자동화하는 npm 패키지가 있습니다.

npm 설치 -g npm-win-upgrade


Microsoft Open Source에서는 위에서 설명한 프로세스를 자동화하는 작은 도구를 작성했습니다. 여기에서 찾 거나 관리자 권한 명령 프롬프트 / PowerShell에서 다음을 실행하여 설치하고 실행할 수 있습니다.

npm install -g npm-windows-upgrade
npm-windows-upgrade

npmWindows에서 업데이트하는 방법은 여러 가지가 있습니다 .

방법 1

  1. 관리자 권한으로 파워 쉘을 열고 다음 명령을 단계별로 실행하십시오.
  2. Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
  3. npm install -g npm-windows-upgrade
  4. npm-windows-upgrade
  5. 여기서 선호하는 npm 버전을 선택할 수 있습니다.
  6. 갈 준비!

방법 2

  1. npm다음 명령 을 사용하여 최신 버전으로 간단히 업그레이드 할 수 있습니다.
  2. npm install npm@latest -g
  3. 또는 npm단순히 실행 의 특정 버전을 원하는 경우
  4. npm install npm@{version} -g 예를 들면 npm install npm@3.3.12 -g

이제 간단히 실행 npm --version하거나 npm -v현재 버전의 npm을 알 수 있습니다.

3.3.12npm거의 모든 패키지에 가장 적합한 버전입니다 .


그래서, TL; DR; 이것은 작동했습니다.

  1. 노드 제거

  2. 명령 프롬프트에서 다음을 실행하십시오. where npm

  3. chocolatey를 통해 npm을 설치했다면 C : \ ProgramData \ chocolatey \ bin \ npm.exe-DELETE it!
  4. 이제 https://nodejs.org/en/download/ 에서 적절한 MSI를 사용하여 NodeJS를 설치 하십시오.
  5. 좋아하는 셸에서 다음을 입력 npm --version합니다. 이제 NodeJS와 함께 제공되는 NPM 버전을 반영해야합니다 (이 문서 작성 당시 버전은 3.10.10 임).

이것이 나를 위해 일한 것입니다 (goofy me!) 나는 chocolatey를 통해 npm을 설치하여 C : \ ProgramData \ chocolatey \ bin \ npm.exe에 chocolatey로 시작된 npm.exe를 만들었습니다. 이것은 npm 버전 1.4.9였으며 NodeJ를 제거하고 다시 설치하는 것을 포함하여 어떤 조치를 취하더라도 업데이트되지 않았습니다.

=======

편집 : 노드 및 npm을 설치하는 더 나은 방법

오늘 (2017 년 6 월 27 일) 현재 노드 및 npm을 설치하고 관리하는 가장 좋은 방법은 https://github.com/coreybutler/nvm-windows에 설명 된대로 nvm (노드 버전 관리자)을 설치하는 것 입니다. nvm이 있으면 모든 노드 버전을 설치하는 것이 매우 쉽습니다.

  1. 선호하는 콘솔 (CMD, Cmder, PowerShell)을 엽니 다.
  2. 유형 nvm install 6.10.2(노드 버전 6.10.2 설치)
  3. 현재 활성 버전을 보려면을 입력하십시오 nvm list. 다음과 같이 인쇄됩니다.

  6.9.3   
* 6.9.2 (Currently using 64-bit executable)
  6.9.1
  6.10.2


Windows 업그레이드 지침을 따라야합니다.

https://www.npmjs.com/package/npm-windows-upgrade

먼저 관리자 권한 PowerShell에서 다음 명령을 실행하여 시스템에서 스크립트를 실행할 수 있는지 확인합니다. PowerShell을 관리자로 실행하려면 시작을 클릭하고 PowerShell을 검색 한 다음 PowerShell을 마우스 오른쪽 단추로 클릭하고 관리자 권한으로 실행을 선택합니다.

  1. Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
  2. npm install --global --production npm-windows-upgrade
  3. 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:

  1. Remove NPM/Node from your Environment Variables, both for user and system.
  2. Close your open console if you have one open, then open a console as administrator
  3. Change directories to %USERPROFILE% -- that's a window's environment variable that takes you to C:\Users\CurrentlyLoggedInUser
  4. Run from the console in %USERPROFILE%, "C:\Program Files\nodejs\npm" install npm -g (you might have yours in the x86 folder)
  5. If this solution would work for you, step 4 would have worked, and npm -v will show a an up-to-date version
  6. 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.


Use npm-windows-upgrade tool to simply upgrade. Steps are provided in the link.


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

  1. Uninstalled NodeJS from Programs & Features with the uninstaller.
  2. Reboot (or you probably can get away with killing all node-related processes from Task Manager).
  3. 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)
  4. Check your %PATH% environment variable to ensure no references to Nodejs or npm exist.
  5. 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.
  6. Reboot, for good measure.

Installed 6.11 nodejs then it worked.


For update node npm on Windows

I have to delete node in:

C:\Users**YOUR USER**\AppData\Roaming

And reinstall node

참고URL : https://stackoverflow.com/questions/26908899/how-do-i-update-npm-on-windows

반응형