Change default global installation directory for n

2019-01-07 01:42发布

In my windows installation PATH includes C:\Program Files\nodejs, where executable node.exe is. I'm able to launch node from the shell, as well as npm. I'd like new executables to be installed in C:\Program Files\nodejs as well, but it seems impossible to achieve.

Setting NODE_PATH and NODE_MODULES variables doesn't change anything: things are still installed in %appdata%\npm by default.

How can I change the global installation path?

标签: node.js npm
11条回答
对你真心纯属浪费
2楼-- · 2019-01-07 02:15

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

查看更多
老娘就宠你
3楼-- · 2019-01-07 02:16

Everything you need is to read npm-folders documentation. I don't want to start my Win notebook now so I cannot verify it, but you should only change prefix to c:\Program Files\nodejs in your config file. If you want to change it globally for all users, edit c:\Program Files\nodejs\npmrc file, otherwise create/edit c:\Users\{username}\.npmrc.

But this change will have probably some side efects so read this discussion before. I think your idea is not a good one.

查看更多
走好不送
4楼-- · 2019-01-07 02:20

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!

查看更多
姐就是有狂的资本
5楼-- · 2019-01-07 02:21

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

查看更多
成全新的幸福
6楼-- · 2019-01-07 02:24

trying to install global packages into C:\Program Files (x86)\nodejs\ gave me Run as Administrator issues, because npm was trying to install into
C:\Program Files (x86)\nodejs\node_modules\

to resolve this, change global install directory to C:\Users\{username}\AppData\Roaming\npm:

in C:\Users\{username}\, create .npmrc file with contents:

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

reference

environment
nodejs x86 installer into C:\Program Files (x86)\nodejs\ on Windows 7 Ultimate N 64-bit SP1
node --version : v0.10.28
npm --version : 1.4.10

查看更多
狗以群分
7楼-- · 2019-01-07 02:29

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

查看更多
登录 后发表回答