node.js Npm 请以 root/管理员身份再次尝试使用此命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22325031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Npm Please try using this command again as root/administrator
提问by HDs Sergiu
I've been desperately trying to install modules using node.js but it always fails getting packages with npm.
我一直在拼命尝试使用 node.js 安装模块,但它总是无法使用 npm 获取包。
I logged in as Administrator and used powershell/cmd with "run as administrator". I also had problems with the registry so I used npm set registry http://registry.npmjs.org/
我以管理员身份登录并使用带有“以管理员身份运行”的 powershell/cmd。我的注册表也有问题,所以我使用了 npm set registry http://registry.npmjs.org/
I tried everything... it just drives me nuts.
我尝试了一切......它只是让我发疯。
Here are the errors:
以下是错误:
npm ERR! Please try running this command again as root/Administrator.
错误!请尝试以 root/管理员身份再次运行此命令。
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "generator-knockout"
npm ERR! cwd D:\Sergiu\Knockout Test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! path D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\block-stream\block-stream.js
npm ERR! fstream_path D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\block-stream\block-stream.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code EPERM
npm ERR! errno 50
npm ERR! stack Error: EPERM, lstat 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\block-stream\block-stream.js'
npm ERR! fstream_stack C:\Program Files\nodejs\node_modules\npm\node_modules\fstream\lib\writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! Error: EPERM, lstat 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\fstream\LICENSE'
npm ERR! { [Error: EPERM, lstat 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\fstream\LICENSE']
npm ERR! errno: 50,
npm ERR! code: 'EPERM',
npm ERR! path: 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\fstream\LICENSE',
npm ERR! fstream_type: 'File',
npm ERR! fstream_path: 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\fstream\LICENSE',
npm ERR! fstream_class: 'FileWriter',
npm ERR! fstream_stack:
npm ERR! [ 'C:\Program Files\nodejs\node_modules\npm\node_modules\fstream\lib\writer.js:284:26',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
回答by Miyuru Sagarage
It turns out that you don't have to run the command again as Administrator, and doing so won't fix the problem.
事实证明,您不必以管理员身份再次运行该命令,这样做并不能解决问题。
Try:
尝试:
npm cache cleanfirst.If that doesn't fix things, take a look in
%APPDATA%\npm-cache, or if you're using PowerShell,$env:APPDATA\npm-cache.
npm cache clean第一的。如果不解决的事情,采取一看
%APPDATA%\npm-cache,或者如果你正在使用PowerShell中$env:APPDATA\npm-cache。
After cleaning the cache, you may still be left with remnants. Manually remove everything in that directory, and try again. This has always fixed things for me.
清理缓存后,您可能仍然会留下残余物。手动删除该目录中的所有内容,然后重试。这总是为我解决问题。
As @Crazzymatt was mentioning, as of the npm@5 version and up, we need to use npm cache verifyinstead of npm cache clean. Or else you will get an error as preceding.
作为@Crazzymatt是提的是,作为新公共管理@ 5及以上版本,我们需要使用npm cache verify的替代npm cache clean。否则,您将收到如前所述的错误。
npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead.
错误!从 npm@5 开始,npm 缓存会从损坏问题中自我修复,并且从缓存中提取的数据保证是有效的。如果您想确保一切都一致,请改用“npm cache verify”。
(Source: MSDN Blog post)
(来源:MSDN 博客文章)
回答by Elektroi
I solve it running as administrator cmd.
Cleaning the cache
npm cache clean -f
And then try to install the package again
我以管理员cmd运行解决了它。清理缓存
npm cache clean -f
然后再次尝试安装包
回答by Ali Katkar
You should run cmd.exe as administrator.
您应该以管理员身份运行 cmd.exe。
Follow the following steps:
请按照以下步骤操作:
- Click Start, click All Programs, and then click Accessories.
- Right-click Command prompt, and then click Run as administrator.
- 单击开始,单击所有程序,然后单击附件。
- 右键单击命令提示符,然后单击以管理员身份运行。
回答by Abraxas
Here is how I fixed this on my Windows (7) Dev. environment. I assume the following...
这是我在 Windows (7) Dev 上修复此问题的方法。环境。我假设以下...
- You are Running Command Prompt, Git Bash, Cmderor your favorite Terminal, as an Administratorby right clicking
- Privileges Permissions have been granted for Read/Write(i.e chmod -777)
- 您正在以管理员身份运行 命令提示符、Git Bash、Cmder或您最喜欢的终端,右键单击
- 权限 已授予读/写权限(即 chmod -777)
Okay, let's get to it:
好的,让我们开始吧:
Update any packages where a version check is returning a warning ("npm WARN"..)for example...
npm update -g npm
npm update -g graceful-fs
Next we want to forcea cache clean. This is flagged by an '--f'or '-f'..
npm cache clean --f
In Widows Explorersearch for the following path
更新版本检查返回警告(“npm WARN”..)的任何包,例如...
npm 更新 -g npm
npm update -g 优雅-fs
接下来我们要强迫一个缓存清理。这由'--f'或'-f'标记..
npm 缓存清理 --f
在Widows Explorer 中搜索以下路径
%APPDATA%\npm-cache
%APPDATA%\npm-缓存
And Deleteit's contents
并删除它的内容
- Start a fresh instance of your Terminal, remembering to 'Right-Click' and 'Run as Administrator', install the packages again.
- 启动终端的新实例,记住“右键单击”和“以管理员身份运行”,再次安装软件包。
Hope this helps someone!!
希望这对某人有帮助!!
回答by Liby George
I was already running the Node Command Window as Administrator. As mentioned by many above, the following command with --f (force) solved my issue.
我已经以管理员身份运行节点命令窗口。正如上面许多人提到的,以下带有 --f (force) 的命令解决了我的问题。
npm cache clean -f
npm 缓存清理 -f
After the Cache Clean, the install was flawless. See the screenshot for reference
在缓存清理之后,安装完美无缺。请参阅屏幕截图以供参考
回答by Nilay Vishwakarma
回答by Joey Eng
If you're using TFS or any other source control for your project that sets your checked in files to readonly mode, then you gotta make sure package.json is checked out before running npm install. I've made this mistake plenty of times.
如果您正在为您的项目使用 TFS 或任何其他源代码控制,将您的签入文件设置为只读模式,那么您必须确保在运行 npm install 之前签出 package.json。我已经犯过很多次这个错误了。
回答by UWU_SANDUN
Try following steps
尝试以下步骤
1. Run this command on Terminal or CMD- npm cache clean
1. 在终端或 CMD 上运行此命令-npm cache clean
2. Go to this folder on windows %APPDATA%\npm-cacheAnd delete folder which you want to install module (Ex:- laravel-elixir) or if you are using PowerShell, $env:APPDATA\npm-cache
2.在windows上进入这个文件夹%APPDATA%\npm-cache并删除你要安装模块的文件夹(例如:-laravel-elixir)或者如果你使用的是PowerShell,$env:APPDATA\npm-cache
3. Then Run your command EX:- npm install laravel-elixir
3.然后运行你的命令 EX:- npm install laravel-elixir
回答by tigerRose
Here is how I fixed the problem in Windows. I was trying to install the CLI for Angular.
这是我在 Windows 中解决问题的方法。我试图为 Angular 安装 CLI。
Turn off firewall and antivirus protections.
Right click the nodejs folder (under Program Files), select Properties (scroll all the way down), click the Security tab, and click all items in the ALLOW column (for All System Packages and any user or group that allows you to add the “allow” checkmark).
Click the Windows icon. Type cmd. Right click the top result and select Run as Administrator. A command window results.
Type npm cache clean. If there is an error, close log files or anything open and rerun.
Type npm install -g @angular/cli (Or whatever npm install command you are using)
Check the installation by typing ng –version (Or whatever you need to verify your install)
关闭防火墙和防病毒保护。
右键单击 nodejs 文件夹(在 Program Files 下),选择 Properties(一直向下滚动),单击 Security 选项卡,然后单击 ALLOW 列中的所有项目(对于所有系统包和任何允许您添加“允许”复选标记)。
单击 Windows 图标。键入 cmd。右键单击顶部结果并选择以管理员身份运行。命令窗口结果。
键入 npm 缓存清理。如果出现错误,请关闭日志文件或打开的任何内容并重新运行。
键入 npm install -g @angular/cli (或您使用的任何 npm install 命令)
通过键入 ng –version 检查安装(或验证安装所需的任何内容)
Good luck! Note: If you are still having problems, check the Path in Environmental Variables. (To access: Control Panel → System and Security → System → Advanced system settings → Environment variables.) My path variable included the following: C:\Users\Michele\AppData\Roaming\npm
祝你好运!注意:如果仍有问题,请检查环境变量中的路径。(访问:控制面板→系统和安全→系统→高级系统设置→环境变量。)我的路径变量包括以下内容:C:\Users\Michele\AppData\Roaming\npm
回答by ThundaPete
I had the same problem, what I did to solve it was ran the cmd.exe as administrator even though my account was already set as an administrator.
我遇到了同样的问题,我为解决它所做的是以管理员身份运行 cmd.exe 即使我的帐户已经设置为管理员。

