npm で electron を Ubuntu18.04 にインストールする際にエラーが出たのでその対処法をメモ程度にまとめます。
まず、npm 及び node のバージョンは次のとおりです。
$ npm -v
6.4.1
$ node -V
v10.10.0
npm、node の導入には "とりあえず Ubuntu で新しい Node.js, npm をインストール" を参考にさせていただきました。
次のコマンドで electron をインストールしようとしたところ、以下のようなエラーが出力されました。
$ sudo npm -g install electron
/usr/local/bin/electron -> /usr/local/lib/node_modules/electron/cli.js
> electron@2.0.9 postinstall /usr/local/lib/node_modules/electron
> node install.js
/usr/local/lib/node_modules/electron/install.js:54
throw err
^
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/electron/dist'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron@2.0.9 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electron@2.0.9 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/tmurakami/.npm/_logs/2018-09-18T10_10_46_444Z-debug.log
調べたところ次のコマンドで electron をインストールすることが出来ました ( オプション --allow-root なしでもインストールは可能でした)。
sudo npm -g install electron --unsafe-perm=true --allow-root
問題の解決に当たって、次のページを参考にしました。
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/electron/.electron' #17268