美文网首页mac下php开发
mac 10.13.6 node.js和cnpm的安装

mac 10.13.6 node.js和cnpm的安装

作者: 小黑胖_ | 来源:发表于2018-10-25 17:13 被阅读0次

一、下载node.js安装包(https://nodejs.org/en/)

image

下载之后,一路傻瓜同意安装即可。

安装完后,检测是否安装成功。打开终端输入命令 node -v,显示node.js的版本号即为安装成功

image

二、cnpm的安装

1.淘宝镜像安装cnpm,在终端输入:

npm install -g cnpm --registry=https://registry.npm.taobao.org

2.如果提示以下信息,说明安装失败:

npm ERR! Unexpected end of JSON input while parsing near '...ttachment":false,"tar'

npm ERR! A complete log of this run can be found in:

npm ERR!     /Users/***/.npm/_logs/2017-11-19T06_56_48_229Z-debug.log

3.如果出现上面的信息,不要慌,依次输入下面三行命令,第三行清除一下安装缓存:

npm set registry https://registry.npm.taobao.org

npm set disturl https://npm.taobao.org/dist

npm cache clean --force

4.上面三行命令完成后,再次输入步骤二的命令:

npm i -g cnpm --registry=https://registry.npm.taobao.org

如果一切正常,输入下面的命令,查询是否安装成功:

cnpm -v

如果出现下面的版本信息,说明cnpm安装成功

cnpm@5.1.1 (/usr/local/lib/node_modules/cnpm/lib/parse_argv.js)

npm@5.5.1 (/usr/local/lib/node_modules/cnpm/node_modules/npm/lib/npm.js)

node@8.9.0 (/usr/local/bin/node)

npminstall@3.2.1 (/usr/local/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)

prefix=/usr/local

darwin x64 16.7.0

registry=http://registry.npm.taobao.org

5.如果步骤4执行完命令后出现以下信息,说明安装失败,需要一个安装的最高权限:

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules

npm ERR! path /usr/local/lib/node_modules

这时,请输入一下命令:

sudo npm install -g cnpm --registry=https://registry.npm.taobao.org --verbose

此时会提示让你输入一个密码,即你的用户开机密码,输入回车即可,如果出现下面的信息(最下面几行)说明安装成功:

npm info lifecycle cnpm@5.1.1~postinstall: cnpm@5.1.1

npm verb unlock done using /Users/lijia/.npm/_locks/staging-3a08f0df5026584d.lock for /usr/local/lib/node_modules/.staging

+ cnpm@5.1.1

added 692 packages in 29.865s

npm verb exit [ 0, true ]

npm info ok

好了,输入下面的命令查询一下吧

cnpm -v

相关文章

网友评论

    本文标题:mac 10.13.6 node.js和cnpm的安装

    本文链接:https://www.haomeiwen.com/subject/leectqtx.html