无法获取"npm install -g"可以在任何包上工作(AppData/Roaming/npm始终为空) [英] Cannot get "npm install -g" to work on any packages (AppData/Roaming/npm always empty)
问题描述
正在Windows 7 Enterprise上运行nodejs.
Running nodejs on Windows 7 Enterprise at work.
每当我安装需要-g访问的node_module时,根据经验,我知道它应该在%AppData $/Roaming/npm
中创建一个* .bat文件,但是由于某种原因,它不再做到了.
Whenever I install a node_module that needs -g access, from experience I know it's supposed to create a *.bat file in %AppData$/Roaming/npm
, but for some reason it no longer does that.
例如,我将运行 npm install gulp -g
,控制台看起来像它已正确安装,但文件不在AppData文件夹中.而且,如果我尝试运行gulp命令,则会收到错误 sh.exe:gulp:命令未找到
.
For example, I will run npm install gulp -g
, console looks like it installed correctly, but the files will not be in the AppData folder. And if I try running a gulp command, I get error sh.exe": gulp: command not found
.
如果在管理员身份控制台中运行 npm install gulp -g
命令,它将把文件安装到管理员(而不是普通用户)的%AppData%文件夹中.因此,如果我通过非管理员用户运行gulp命令,仍然会收到错误 sh.exe:gulp:命令未找到
.
If I run the npm install gulp -g
command in Console As Administrator, it installs the files into the %AppData% folder of the administrator (instead of the regular user). So if I run the gulp command through my non-administrator user, I still get error sh.exe": gulp: command not found
.
有什么想法吗?
推荐答案
找到的解决方案:
(1)运行命令: npm config get prefix
,输出为 C:\ Program Files(x86)\ Git \ local
.不知道为什么将它设置为此,因为它不是默认值.
(1) Upon running the command: npm config get prefix
, output is C:\Program Files (x86)\Git\local
. No idea why it was set to this, as it's not the default.
但是我使用以下代码更改了它: npm config set prefix"$ APPDATA \ npm"
.
But I changed it using: npm config set prefix "$APPDATA\npm"
.
现在,当我安装--g模块时,即. npm install gulp -g
,它将安装到此所需目录中,不再引发 EPERM
和 ENOENT
错误.
Now when I install a --g module, ie. npm install gulp -g
, it installs into this desirable directory, no longer throwing EPERM
and ENOENT
errors.
(2)仍然需要为npm文件夹添加一个 PATH
条目.命令 export PATH = $ PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm
暂时有效,但是如果关闭控制台并再次打开,则可能无法保存(如果您不是管理员).
(2) Still need to add a PATH
entry for the npm folder. The command export PATH=$PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm
works temporarily, but if you close console and open it again, might not be saved (if you are not an administrator).
但是您也可以使用 echo'export PATH = $ PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm'>>〜/.bash_profile
,它将创建一个 .bash_profile
文件,该文件在每次打开控制台时都运行.因此,从这一点来看,它应该自动添加所需的 PATH
条目.
But you can also use echo 'export PATH=$PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm' >> ~/.bash_profile
, which will create a .bash_profile
file, which is run each time as your console is opened. So from this point, it should automatically add the required PATH
entry.
这篇关于无法获取"npm install -g"可以在任何包上工作(AppData/Roaming/npm始终为空)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!