2017年3月19日
Electron环境搭建(mac篇)
摘要: 首先在这里先说一句,本次搭建环境是mac上,不是windows,如果您是windows仅提供参考,
本文简单介绍Mac上安装node,npm及electron的过程。
由于mac本身就带node,我的node 版本是4.4.4,附带的npm版本是2.15.6我也没有升级,如果你想查看自己的版本请打开控制台
输入以下命令
node -v
同样道理 查看 npm版本号输入
npm -v 在这里就不过多演示了 ,会写hello word 的人都能会,
接下来安装 ,说起安装好头大,输入npm install -g electron-prebuilt
进行安装。
但是你发现并没有什么卵用,
报错内容:
appledeMBP:~ apple$ npm install -g nrm
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "nrm"
npm ERR! node v4.4.4
npm ERR! npm v2.15.1
npm ERR! code ECONNRESET
npm ERR! network tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:8118
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! Please include the following file with any support request:
npm ERR! /Users/apple/npm-debug.log
这个时候能翻墙就翻墙,千万别逞能,与其花那么多时间重复造轮子,不如直接简单粗暴,
你如果不能翻墙,那请往下看,
那我们就只好走国内的了,国内知名淘宝镜像,nrm 先安装切换npm到 淘宝的,
npm install -g cnpm --registry=https://registry.npm.taobao.org
之后切换,成功后 记得身份切换成超级管理员,mac上要记得sudo哦 ,
sudo -i 切换管理身份
开始安装 npm install –g electron-prebuilt
接着他开始安装了!!!!!
请看以下代码片段
Last login: Mon Feb 6 12:57:14 on ttys001
appledeMBP:~ apple$ sudo -i
Password:
appledeMBP:~ root#
appledeMBP:~ root#
appledeMBP:~ root#
appledeMBP:~ root# npm install --g electron-prebuilt
npm WARN deprecated electron-prebuilt@1.4.13: electron-prebuilt has been renamed to electron. For more details, see http://electron.atom.io/blog/2016/08/16/npm-install-electron
/usr/local/bin/electron -> /usr/local/lib/node_modules/electron-prebuilt/cli.js
> electron-prebuilt@1.4.13 postinstall /usr/local/lib/node_modules/electron-prebuilt
> node install.js
electron-prebuilt@1.4.13 /usr/local/lib/node_modules/electron-prebuilt
├── extract-zip@1.6.0 (debug@0.7.4, mkdirp@0.5.0, yauzl@2.4.1, concat-stream@1.5.0)
└── electron-download@3.3.0 (semver@5.3.0, home-path@1.0.3, minimist@1.2.0, rc@1.1.6, debug@2.6.0, path-exists@2.1.0, sumchecker@1.3.0, fs-extra@0.30.0, nugget@2.0.1)
appledeMBP:~ root#
appledeMBP:~ root#
appledeMBP:~ root# electron -v
v1.4.13
appledeMBP:~ root#
最后查看是否安装成功 electron -v 最后成功了,
总结一下 electron 在mac上面安装有些繁琐, 一开始我安装失败了 后来在github上直接抓下来,发现抓到的是人家吐出来的,自己根本用不了,近期会用electron搞一些小东西,后续博客会慢慢补充,今天又是代码满满的一天。再见