首先安装node.js,会集成npm,npm是node的包管理工具,node package management的缩写,cnpm是淘宝集成外网包在国内网关内的镜像,因此安装会快一些,视为首选。
1.安装完nodejs后打开mac终端检查npm版本 npm -v
2.安装cnpm淘宝镜像,执行
npm install -g cnpm --registry=https://registry.npm.taobao.org
3.安装报错
npm ERR! Darwin 16.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "cnpm" "--registry=https://registry.npm.taobao.org" "--verbose"
npm ERR! node v6.11.0
npm ERR! npm v3.10.10
npm ERR! path ../lib/node_modules/cnpm/bin/cnpm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall symlink
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/cnpm/bin/cnpm' -> '/usr/local/bin/cnpm'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, symlink '../lib/node_modules/cnpm/bin/cnpm' -> '/usr/local/bin/cnpm'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/cnpm/bin/cnpm',
npm ERR! dest: '/usr/local/bin/cnpm' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm verb exit [ -13, true ]
npm ERR! Please include the following file with any support request:
npm ERR! /Users/xxx/npm-debug.log
4.发现Please try running this command again as root/Administrator.这样的提示,改用命令
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
(sudo命令是让管理员允许一般权限的用户执行一些命令,需要用户输入密码)
安装成功