Programing

nvm을 사용하여 npm 버전을 어떻게 변경합니까?

lottogame 2020. 4. 28. 08:17
반응형

nvm을 사용하여 npm 버전을 어떻게 변경합니까?


노드 작업을 위해 최신 버전의 nodeJS를 설치하기 위해 NVM을 사용하고 있습니다. 별도의 버전을 설치하고 전환 할 때 완전히 작동합니다. 또한 노드 이진과 함께 각 로컬 ... / bin 폴더 내에 최신 버전의 NPM을 설치합니다. 그러나 사용중인 NPM 버전을 전환 할 수있는 방법이없는 것 같습니다 (적어도 이해할 수는 없습니다).

내가 생각할 수있는 유일한 해결책은 기본 설정 인 바이너리 (NVM과 함께 노드를 처음 설치할 때 설치된 NPM)를 삭제하고 최신 NPM 바이너리를 배치하는 것입니다. 그러나이 작업을 수행하는 더 좋은 방법이 있는지 궁금합니다.


편집 : 새로운 답변 에서 언급 했듯이이 질문에 처음 대답 한 지 몇 년이 지난 지금이 명령이 있습니다.

nvm에는 이제 npm을 업데이트하는 명령이 있습니다. 그건 nvm install-latest-npmnvm install --latest-npm.

nvm install-latest-npm: npm현재 노드 버전 에서 최신 작업 으로 업그레이드하려고합니다.

nvm install --latest-npm: 설치 후 지정된 노드 버전에서 최신 작동 npm으로 업그레이드하십시오.

아래는이 질문에 대한 정답의 이전 개정판입니다.

이 질문이 처음 제기 된 지 3 년이 지난 지금은 그 대답이 훨씬 간단 해 보입니다. nvm이 설치된 버전을 업데이트하십시오 ~/.nvm/versions/node/[your-version]/lib/node_modules/npm.

방금 npm 2.14.7과 함께 제공되는 노드 4.2.2를 설치했지만 npm 3을 사용하고 싶습니다.

cd ~/.nvm/versions/node/v4.2.2/lib
npm install npm

쉬운!

그리고 네, 이것은 npm뿐만 아니라 특정 버전의 노드에 대해 "글로벌"되기를 원하는 모든 모듈에서 작동합니다.


편집 1 : 최신 버전에서는 npm -g스마트하고 시스템 전역 경로 대신 위의 경로에 모듈을 설치합니다.


의견을 지적 해 주신 @philraj에게 감사드립니다.


nvm은 npm을 처리하지 않습니다.

따라서 여전히 많은 패키지에 의존하는 노드 0.4.x를 설치하고 NPM을 사용하려는 경우에도 npm 1.0.x를 사용할 수 있습니다.

노드 0.6.x (npm 1.1.x와 함께 제공)를 설치하고 npm과 함께 nvm을 설치하십시오.

npm install nvm
. ~/nvm/nvm.sh

nvm과 함께 노드 0.4.x를 설치하십시오.

nvm install v0.4.12
nvm use v0.4.12

install.sh를 사용하여 npm을 설치하십시오 ( -L리디렉션을 따르는 매개 변수에 유의하십시오 ).

curl -L https://npmjs.org/install.sh | sh

이것은 노드 0.4.12를 감지하고 ~ / nvm / v0.4.12 / lib / node_modules 폴더에 npm 1.0.106을 설치하고 nvm에 대한 symlink를 만듭니다.

~/nvm/v0.4.12/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js

npm을 실행하려고해도 여전히 오류가 발생하지만 nvm use v0.4.12다시 수행 하면 이제 작동합니다.


nvm에는 이제 npm을 업데이트하는 명령이 있습니다. 그건 nvm install-latest-npmnpm install --latest-npm.


npm install npm@x.x.x -g
npm install npm@5.4.0 -g

나는 Windows에 있고이 물건을 작동시킬 수 없었습니다. 파일에 문제가 계속 발생했습니다. 그래도 작동했습니다.

cd %APPDATA%\nvm\v8.10.0           # or whatever version you're using
mv npm npm-old
mv npm.cmd npm-old.cmd
cd node_modules\
mv npm npm-old
cd npm-old\bin
node npm-cli.js i -g npm@latest

cd %APPDATA%\nvm\v8.10.0 # or whatever version you're using
rm npm-old
rm npm-old.cmd
cd node_modules\
rm -rf npm-old

그리고 붐, 나는 사업에 돌아왔다.


Linux 기반 OS에서 npm 버전을 변경하는 것은 아직 간단한 명령 프로세스가 아닙니다. 이전 버전의 npm으로 다시 전환하기 위해 다음을 수행했습니다. 이것은 모든 버전의 npm이 작동하도록 작동해야합니다. 먼저 사용하려는 npm 버전을 설치하십시오.

sudo npm install -g npm@X.X.X

/ usr / local / bin /에서 sym 링크를 제거하십시오.

sudo rm /usr/local/bin/npm

설치 한 원하는 npm 버전을 사용하여 sym 링크를 다시 작성하십시오.

sudo ln -s /usr/bin/npm@X.X.X /usr/local/bin/npm

By looking at www.npmjs.com/install.sh I found there is a way to install a specific version by setting an environment-variable

export npm_install="2.14.14"

Then run the download-script as described at npmjs.com:

curl -L https://www.npmjs.com/install.sh | sh

If you omit setting the npm_install variable, then it will install the the version they have marked as latest


In windows, run your terminal as admin (in case there are permission issues as I had). Then use a specific node version (say 7.8.0) by

nvm use 7.8.0

then update your npm to desired specific version by

npm install -g npm@5.0.3

What about npm i -g npm? Did you try to run this as well?


Slight variation on the above instructions, worked for me. (MacOS Sierra 10.12.6)

npm install -g npm@3.10.10
rm /usr/local/bin/npm
ln -s ~/.npm-packages/bin/npm /usr/local/bin/npm
npm --version

I had same issue after installing nvm-windows on top of existing Node installation. Solution was just to follow the instructions:

You should also delete the existing npm install location (e.g. "C:\Users\AppData\Roaming\npm") so that the nvm install location will be correctly used instead.

Installation & Upgrades


NVM Installation & usage on Windows

Below are the steps for NVM Installation on Windows:

NVM stands for node version manager, which will help to switch the your node versions for specific use. It also allows the user to work with multiple npm and node versions.

Install nvm setup. Use command "nvm list" to check list ofinstalled node version. Type "nvm use version number[6.9.3]" to switch versions. For more info


  1. find the node and npm version you want to use from here https://nodejs.org/en/download/releases/
  2. nvm use 8.11.4
  3. you already got the npm 5.6(solid and good)

참고URL : https://stackoverflow.com/questions/9755841/how-can-i-change-the-version-of-npm-using-nvm

반응형