简体   繁体   English

在 Mac OS 10.13 上安装 Angular

[英]Installing Angular on Mac OS 10.13

I'm trying to follow the quickstart on running Angular locally (on MacOS 10.13.6).我正在尝试按照快速入门在本地运行 Angular(在 MacOS 10.13.6 上)。 With the first command, I already get some errors:使用第一个命令,我已经得到了一些错误:

npm install -g @angular/cli

Output: Output:

npm ERR! path /usr/local/lib/node_modules/@angular/cli/node_modules/socks
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@angular/cli/node_modules/socks'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@angular/cli/node_modules/socks']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/@angular/cli/node_modules/socks\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path:
npm ERR!    '/usr/local/lib/node_modules/@angular/cli/node_modules/socks' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2019-03-12T23_55_12_063Z-debug.log

Running with sudo gives me the following:使用 sudo 运行会得到以下信息:

gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/.node-gyp'
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" "--module_name=fse" "--module_path=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64" "--napi_version=3" "--node_abi_napi=napi"
gyp ERR! cwd /usr/local/lib/node_modules/@angular/cli/node_modules/fsevents
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node --module_name=fse --module_path=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64 --napi_version=3 --node_abi_napi=napi' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:189:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:970:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
node-pre-gyp ERR! System Darwin 17.7.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/node_modules/node-pre-gyp/bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/@angular/cli/node_modules/fsevents
node-pre-gyp ERR! node -v v10.15.3
node-pre-gyp ERR! node-pre-gyp -v v0.10.3
node-pre-gyp ERR! not ok 
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node --module_name=fse --module_path=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64 --napi_version=3 --node_abi_napi=napi' (1)

My node version is LTS (10.15.3).我的节点版本是 LTS (10.15.3)。 Any idea what's causing this and how to get angular to run on Mac?知道是什么原因造成的,以及如何让 angular 在 Mac 上运行?

you will need the write permission in node_modules directory: 您将需要在node_modules目录中具有写许可权:

sudo chown -R $(whoami) ~/.npm

Running sudo when installing npm will give you problems in the long run, so just run the command above. 从长远来看,在安装npm时运行sudo会给您带来问题,因此只需运行上面的命令即可。

npm throws error without sudo npm抛出没有sudo的错误

sudo npm install -g @angular/cli

以sudo权限运行,您应该会很好。

/usr/local文件夹需要root权限,请尝试使用sudo安装它:

sudo npm install -g @angular/cli

As mentioned in the comments, using sudo isn't good practice, I had to run the following 3 commands to gain ownership of the relevant directories:正如评论中提到的,使用 sudo 不是一个好习惯,我必须运行以下 3 个命令来获得相关目录的所有权:

sudo chown -R $(whoami) ~/.npm  
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/bin

Now I can install Angular CLI (or any other node packages) globally, without the need for sudo.现在我可以全局安装 Angular CLI(或任何其他节点包),而不需要 sudo。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM