node.js 无法在 Mac 上安装 angular-cli
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48255269/
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
Can't install angular-cli on Mac
提问by Menelaos Kotsollaris
This is probably very trivial, but I am hitting my head against the wall while I am trying to (unsuccessfully) install angular-cli.
这可能是微不足道的,但是当我尝试(失败)安装 angular-cli 时,我的头撞到了墙上。
I am following the official angular-cli documentation here.
我在这里关注官方angular-cli 文档。
mkotsollariss-MacBook-Pro:~ mkotsollaris$ npm -v
5.6.0
mkotsollariss-MacBook-Pro:~ mkotsollaris$ node -v
v8.9.4
Then I run npm install -g angular-cli which gives me:
然后我运行 npm install -g angular-cli 这给了我:
mkotsollariss-MacBook-Pro:~ mkotsollaris$ npm install -g angular-cli
npm WARN deprecated [email protected]: angular-cli has been renamed to @angular/cli. Please update your dependencies.
npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN @angular/[email protected] requires a peer of rxjs@^5.0.1 but none is installed. You must install peer dependencies yourself.
npm ERR! path /Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rmdir
npm ERR! Error: EACCES: permission denied, rmdir '/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular'
npm ERR! { Error: EACCES: permission denied, rmdir '/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular'
npm ERR! stack: 'Error: EACCES: permission denied, rmdir \'/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rmdir',
npm ERR! path: '/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mkotsollaris/.npm/_logs/2018-01-14T23_11_22_610Z-debug.log
mkotsollariss-MacBook-Pro:~ mkotsollaris$ ng
-bash: ng: command not found
I think I have tried almost everything on the web, and still can't make this to work.
我想我已经尝试了网络上的几乎所有内容,但仍然无法使其正常工作。
My OS is MacOS High Sierra 10.13.2.
我的操作系统是MacOS High Sierra 10.13.2.
Any idea what am I missing here?
知道我在这里缺少什么吗?
回答by Menelaos Kotsollaris
After several tries, I finally installed angular-clisuccessfully via nvm. In detail:
经过几次尝试,我终于angular-cli通过nvm安装成功。详细:
Install nvm:
安装nvm:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
export NVM_DIR="/Users/mkotsollaris/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm --version
0.33.0
Then install node through nvm:
然后通过nvm以下方式安装节点:
nvm install stable
nvm install node
Thereafter, install angular-cli:
此后,安装 angular-cli:
npm install -g @angular/cli
mkotsolarissMBP:myapp mkotsollaris$ ng -v
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 1.6.5
Node: 9.4.0
OS: darwin x64
Angular: 5.2.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.6.5
@angular-devkit/build-optimizer: 0.0.41
@angular-devkit/core: 0.0.28
@angular-devkit/schematics: 0.0.51
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.5
@schematics/angular: 0.1.16
typescript: 2.5.3
webpack: 3.10.0
mkotsolarissMBP:myapp mkotsollaris$
Verify that ng works properly:
验证 ng 是否正常工作:
ng new my-project
cd my-project
ng serve
The app will start on localhost:4200.
该应用程序将启动localhost:4200。
回答by Seema Rawal
i faced similar issue while installing angular-cli on Mac Mojave.
我在 Mac Mojave 上安装 angular-cli 时遇到了类似的问题。
Correct installation steps are:
正确的安装步骤是:
- Install npm using package manager.
- above step sets the directory owner of
/usr/local/lib/node_modules/to root. execute below command to set the owner to your user:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}npm install -g @angular/cli(avoid using sudo)
- 使用包管理器安装 npm。
- 上面的步骤将目录所有者设置
/usr/local/lib/node_modules/为 root。 执行以下命令将所有者设置为您的用户:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}npm install -g @angular/cli(避免使用sudo)
回答by Sagiruddin Mondal
Try this:
尝试这个:
sudo npm install -g @angular/cli
回答by Krishna Teja Ayinala
To get rid of access errors, these steps can help:
要消除访问错误,这些步骤可以提供帮助:
Step1: Homebrew installation[https://brew.sh/]: (on terminal)
Step1: Homebrew 安装[ https://brew.sh/]: (在终端上)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step2: brew install node
Step2:brew安装节点
Check version: node -v, npm -v
Step3: brew install -g angular-cli
步骤 3: brew install -g angular-cli
Check version: ng --version
Step4: ng new First-App
Step4: ng 新的 First-App
回答by Anthony Agbator
After going back and forth i used homebrew. Just run: "sudo brew install angular-cli" If you have homebrew installed, it solved all my problems including node-sass issues on angular 7
来回后,我使用自制软件。只需运行:“sudo brew install angular-cli”如果您安装了自制软件,它就解决了我的所有问题,包括 angular 7 上的 node-sass 问题
回答by Dinesh Nisshanka
These are the codes I used
这些是我使用的代码
sudo npm uninstall -g angular-cli
sudo npm uninstall -g @angular/cli
sudo npm cache clean --force
npm install -g @angular/cli
alias ng="~/node_modules/@angular/cli/bin/ng"
for check
检查
ng --version
回答by ABAKARIM MAROUANE
Error: EACCES: permission denied, rmdir '/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular'
you do not have permissions to access the directories node_modules.
Error: EACCES: permission denied, rmdir '/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular'
you do not have permissions to access the directories node_modules.
your process want to make changes to your directories and it is not allowed to access you can easily be in super user (admin), have access permission is thrown the command so that the processur can modify the node_modules angular.
您的进程想要更改您的目录并且不允许访问您可以轻松地成为超级用户(管理员),具有访问权限的命令会被抛出,以便进程可以修改 node_modules 角度。
sudo npm install -g @angular/cli
sudo npm install -g @angular/cli
回答by Divyanshu Rawat
This worked for me.
这对我有用。
sudo npm install --unsafe-perm -g @angular/cli
回答by Elialber Lopes
This seems like a problem with your node/npm and not with Angular CLI.
这似乎是您的节点/npm 的问题,而不是 Angular CLI 的问题。
Please have a look at the fixing npm permissions page, common errors page, npm issue tracker, or open a new issue if the problem you are experiencing isn't known.
请查看修复 npm 权限页面、常见错误页面、npm 问题跟踪器,如果您遇到的问题未知,请打开一个新问题。
回答by Andrew Salib
I've faced a problem very similar to this one before. It's most likely that you installed Node & NPM as root etc.
我以前遇到过与此非常相似的问题。很可能您以 root 等身份安装了 Node 和 NPM。
You should attempt to re-install Node & NPM without sudo, one of these scripts might work for you: https://gist.github.com/isaacs/579814
您应该尝试在没有 的情况下重新安装 Node 和 NPM sudo,这些脚本之一可能适合您:https: //gist.github.com/isaacs/579814
Then retry npm i -g angular-cliand hopefully should work no problems.
然后重试npm i -g angular-cli,希望应该没有问题。
Best of luck!
祝你好运!


