IT story

Windows에서 node.js 모듈의 기본 글로벌 설치 디렉토리를 변경 하시겠습니까?

hot-time 2020. 7. 13. 07:55
반응형

Windows에서 node.js 모듈의 기본 글로벌 설치 디렉토리를 변경 하시겠습니까?


내 Windows 설치 PATH에는 C:\Program Files\nodejs실행 파일 node.exe포함되어 있습니다. node쉘뿐만 아니라 시작할 수 npm있습니다. 새로운 실행 파일도 설치하고 싶지만 C:\Program Files\nodejs달성하기가 불가능합니다.

설정 NODE_PATHNODE_MODULES변수는 아무 것도 변경하지 않습니다 %appdata%\npm. 기본적으로 여전히 설치되어 있습니다.

글로벌 설치 경로는 어떻게 변경합니까?


필요한 것은 npm-folders문서 를 읽는 입니다. 나는 그것을 확인할 수 있도록 지금 내 승리의 노트북을 시작하고 싶지 않지만, 당신은 단지 변경해야합니다 prefix으로 c:\Program Files\nodejs설정 파일에. 모든 사용자에 대해 전체적으로 변경하려면 c:\Program Files\nodejs\npmrc파일을 편집 하고 그렇지 않으면 작성 / 편집하십시오 c:\Users\{username}\.npmrc.

그러나이 변경으로 인해 일부 부작용이있을 수 있으므로이 논의를 먼저 읽으십시오 . 나는 당신의 생각이 좋지 않다고 생각합니다.


설치하려고 세계 로 포장하는 것은 C:\Program Files (x86)\nodejs\나에게 준 관리자로 실행 NPM은에 설치하려고했기 때문에, 문제
C:\Program Files (x86)\nodejs\node_modules\

이를 해결하려면 글로벌 설치 디렉토리를 C:\Users\{username}\AppData\Roaming\npm다음으로 변경하십시오 .

에서 내용이 포함 된 파일을 C:\Users\{username}\만듭니다 .npmrc.

prefix = "C:\\Users\\{username}\\AppData\\Roaming\\npm"

참고

Windows 7 Ultimate N 64 비트 SP1의 환경
nodejs x86 설치 프로그램 : v0.10.28 : 1.4.10C:\Program Files (x86)\nodejs\
node --version
npm --version


당신은 이것에 대한 나의 대답을 다른 질문에 대한 나의 대답 에서 볼 수 있습니다 .


Windows에서 글로벌 설치 경로는 실제로 사용자의 프로파일 디렉토리에 있습니다.

  • %USERPROFILE%\AppData\Roaming\npm
  • %USERPROFILE%\AppData\Roaming\npm-cache
  • 경고 : 다른 사용자로 시간 초과 이벤트 또는 기타 자동화를 수행 npm install하는 경우 해당 사용자로 실행해야합니다 . 일부 모듈 / 유틸리티는 전체적으로 설치해야합니다.
  • 설치자 버그 :이 디렉토리를 작성하거나 ...\npm사용자 경로에 디렉토리를 직접 추가해야 할 수도 있습니다 .

모든 사용자의 "전역"위치를보다 적절한 공유 전역 위치 %ALLUSERSPROFILE%\(npm|npm-cache)로 변경하려면 (관리자로서 수행) :

  • 만들 [NODE_INSTALL_PATH]\etc\디렉토리를
    • 이것은 npm config --global ...행동 을 시도하기 전에 필요합니다
  • npm 모듈의 전역 (관리자) 위치를 만듭니다.
    • C:\ProgramData\npm-cache -npm 모듈이 여기에 있습니다
    • C:\ProgramData\npm -전 세계적으로 설치된 모듈의 바이너리 스크립트가 여기에 있습니다
    • C:\ProgramData\npm\node_modules -전 세계적으로 설치된 모듈이 여기에 있습니다
    • 권한을 적절하게 설정하십시오
      • 관리자 : 수정
      • 인증 된 사용자 : 읽기 / 실행
  • 글로벌 구성 설정 (관리자 명령 프롬프트)
    • npm config --global set prefix "C:\ProgramData\npm"
    • npm config --global set cache "C:\ProgramData\npm-cache"
  • 추가 C:\ProgramData\npm시스템의 PATH 환경 변수에

사용자의 "전역"위치를 %LOCALAPPDATA%\(npm|npm-cache)대신 경로 로 변경하려면 다음을 수행하십시오 .

  • 필요한 디렉토리를 만듭니다
    • C:\Users\YOURNAME\AppData\Local\npm-cache -npm 모듈이 여기에 있습니다
    • C:\Users\YOURNAME\AppData\Local\npm - binary scripts for installed modules will go here
    • C:\Users\YOURNAME\AppData\Local\npm\node_modules - globally installed modules will go here
  • Configure npm
    • npm config set prefix "C:\Users\YOURNAME\AppData\Local\npm"
    • npm config set cache "C:\Users\YOURNAME\AppData\Local\npm-cache"
  • Add the new npm path to your environment's PATH.
    • setx PATH "%PATH%;C:\Users\YOURNAME\AppData\Local\npm"

Building on the installation concept of chocolatey and the idea suggested by @Tracker, what worked for me was to do the following and all users on windows were then happy working with nodejs and npm.

Choose C:\ProgramData\nodejs as installation directory for nodejs and install nodejs with any user that is a member of the administrator group.

Create a folder called npm-cache at the root of the installation directory, which after following above would be C:\ProgramData\nodejs\npm-cache.

Create a folder called etc at the root of the installation directory, which after following above would be C:\ProgramData\nodejs\etc.

Set NODE environment variable as C:\ProgramData\nodejs.

Set NODE_PATH environment variable as C:\ProgramData\nodejs\node_modules.

Ensure %NODE% environment variable previously created above is added (or its path) is added to %PATH% environment variable.

Edit %NODE_PATH%\npm\npmrc with the following content prefix=C:\ProgramData\nodejs

From command prompt, set the global config like so...

npm config --global set prefix "C:\ProgramData\nodejs"

npm config --global set cache "C:\ProgramData\nodejs\npm-cache"

It is important the steps above are carried out preferably in sequence and before updating npm (npm -g install npm@latest) or attempting to install any npm module.

Performing the above steps helped us running nodejs as system wide installation, easily available to all users with proper permissions. Each user can then run node and npm as required.


You should use this command to set the global installation flocation of npm packages

(git bash) npm config --global set prefix </path/you/want/to/use>/npm

(cmd/git-cmd) npm config --global set prefix <drive:\path\you\want\to\use>\npm

You may also consider the npm-cache location right next to it. (as would be in a normal nodejs installation on windows)

(git bash) npm config --global set cache </path/you/want/to/use>/npm-cache

(cmd/git-cmd) npm config --global set cache <drive:\path\you\want\to\use>\npm-cache


The default global folder is C:\Users\{username}\AppData\Roaming\npm. You can create (if it doesn't exist) a .npmrc file in C:\Users\{username}\ and add prefix = "path\\to\\yourglobalfolder". Note that, in windows, the path should be separated by double back-slash.


Using a Windows symbolic link from the C:\Users{username}\AppData\Roaming\npm and C:\Users{username}\AppData\Roaming\npm-cache paths to the destination worked great for me.

How to add a symbolic link

enter image description here


In Windows, if you want to move the npm or nodejs folder in disk C to another location, but it still makes sure node and npm works well, you can create symlink like this: Open Command Prompt:

mklink /D "your_location_want_to_create_symlink" "location_of_node_npm_file"

Example:

mklink /D "C:\Users\MyUser\AppData\Roaming\npm" "D:\Nodejs Data\npm"

Now you've created a symlink for npm folder, this symlink will refer to D:\Nodejs Data\npmEverything will work well.


I tried most of the answers here nothing seems to work in my case. So i changed the Temp location in my env variables to C:\npm. Then it started to work. This is not a good idea but a temporary solution.


Delete node folder completely from program file folder. Uninstall node.js and then reinstall it. change Path of environment variable PATH. delete .npmrc file from C:\users\yourusername


it does not require much configurations just go to advanced system settings copy the path where you have installed your node and just create an environment variable and check with node -v command in your prompt!


To Change the default global installation directory for node.js(npm) modules in Windows, You need to fix 2 paths.

First check the current path where node modules are installing, when you try to install them globally by using following command :

npm list -g --depth=0

It will return you the current path where node modules are installing right now. Example: D:\vsc\typescript

Now visit the following path to see npm and npm-cache folder. C:\Users\username(OR Number)\AppData\Roaming

In Roaming folder of your C drive you will find npm and npm-cache folder. Click on the + npm + folder and select the path[Just click on the bar path will be selected automatically, copy it ].This is a path image which you need to select

Once you copy this path set this to the environment variables, with a variable name Path(anything you can select as a name). Now you have set the path for your npm folder, now this is the time to set prefix. Go inside npm folder and check if node_module folder exist, if not create a new folder named as node_modules. You all global modules will come in this folder after completing all steps.

Final Step: Go to CMD and right the following command:

npm set prefix C:\Users\username(Number)\AppData\Roaming\npm\node_modules

Again this is the same path we selected for environment variable, we are just adding one more folder in the path and that is node_module.

All Set....Try Now...It will work..


Find the current path of your global node package installation by following command.

npm list -g --depth=0

Change this path to correct path by following command.

npm set prefix C:\Users\username(Number)\AppData\Roaming\npm\node_modules

It worked for me. Read my previous answer for better understanding.


  • Step 1: npm config get prefix

    • Default Path is : %USERPROFILE%\AppData\Roaming\npm
  • Step 2: npm config get cache

    • Default Path is : %USERPROFILE%\AppData\Roaming\npm-cache
  • Step 3: npm config set prefix <Your New Location>\npm

    • example npm config set prefix C:\\dev\\node\\npm
  • Step 4: npm config set cache <Your New Location>\npm-cache

    • example npm config set cache C:\\dev\\node\\npm-cache

    Run steps 1 & 2 again to check whether the paths are updated as required

    Thats it. Whenever you install global packages you should see them installed inside \npm\node_modules

참고URL : https://stackoverflow.com/questions/19874582/change-default-global-installation-directory-for-node-js-modules-in-windows

반응형