ElectronをMacにインストールする方法

MacOS 環境で Electron を使うためのインストール手順について解説します。

  1. Homebrew をインストールする。
  2. node.js をインストールする。
  3. Electron をインストールする。

node.js のインストール

HomeBrew の brew コマンドを使って、node.js をインストールします。

% brew install node

を実行します。

% brew install node
 
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/cask, homebrew/core).
==> New Formulae
python-yq
==> Updated Formulae
readline ✔              cimg                    exploitdb               hevea                   lynis                   php-cs-fixer            swiftformat
adr-tools               clingo                  faas-cli                hlint                   memcached               protobuf@2.6            telegraf
annie                   clojurescript           flow                    hub                     menhir                  py2cairo                terragrunt
ansible                 conan                   flyway                  hugo                    mill                    py3cairo                the_platinum_searcher
apache-opennlp          convox                  fmt                     hyperscan               mkcert                  quicktype               tox
ark                     creduce                 folly                   imagemagick             mkdocs                  rabbitmq                txr
aws-elasticbeanstalk    csvkit                  fuseki                  imagemagick@6           node                    rancher-cli             uwsgi
b2-tools                cython                  get_iplayer             jenkins                 ntl                     rocksdb                 vim
baresip                 darksky-weather         gmt                     jhipster                octave                  roll                    vowpal-wabbit
bats-core               diffoscope              gnatsd                  landscaper              openapi-generator       s3fs                    wandio
bgpstream               dlib                    gobuster                libgit2                 opencv                  scour                   webpack
cake                    dynare                  goreleaser              libqalculate            opendetex               sfk                     wine
cargo-completion        emscripten              gron                    libtrace                osquery                 sshrc                   wireguard-tools
ceres-solver            ephemeralpg             hadolint                linkerd                 percona-toolkit         suite-sparse            wtf
cfr-decompiler          ethereum                hana                    llvm                    pgloader                sundials                xonsh
==> Renamed Formulae
saltstack -> salt
==> Deleted Formulae
artifactory-cli-go                                                                   wry
 
==> Installing dependencies for node: icu4c
==> Installing node dependency: icu4c
==> Downloading https://homebrew.bintray.com/bottles/icu4c-62.1.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring icu4c-62.1.sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS provides libicucore.dylib (but nothing else).
 
If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.zshrc
 
For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/icu4c/lib
    CPPFLAGS: -I/usr/local/opt/icu4c/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/icu4c/lib/pkgconfig
 
==> Summary
🍺  /usr/local/Cellar/icu4c/62.1: 250 files, 67.3MB
==> Installing node
==> Downloading https://homebrew.bintray.com/bottles/node-10.6.0.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring node-10.6.0.sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/node/10.6.0: 6,793 files, 60MB
  • インストールが正常に完了したかどうか確認するには、which コマンドを使って、node と npm にパスが通っているか確認します。
% which node
/usr/local/bin/node
% which npm
/usr/local/bin/npm

正常にインストールが完了していれば上記のように、node と npm のパスが表示されます。

Electron のインストール

次に、Electron をインストールします。

% npm install electron
 
> electron@2.0.4 postinstall /Users/user/node_modules/electron
> node install.js
 
Downloading SHASUMS256.txt
[============================================>] 100.0% of 5.33 kB (5.33 kB/s)
npm WARN saveError ENOENT: no such file or directory, open '/Users/user/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/Users/user/package.json'
npm WARN user No description
npm WARN user No repository field.
npm WARN user No README data
npm WARN user No license field.
 
+ electron@2.0.4
added 148 packages from 123 contributors and audited 217 packages in 45.28s
found 0 vulnerabilities

which electron コマンドを実行して、以下のように表示されれば、Electron のインストールは完了しています。

% which electron
/usr/local/bin/electron
 
% electron -v
v1.4.13

Electron 最新バージョンの確認方法

% npm view electron dist-tags
 
{
  latest: '6.0.10',
  beta: '7.0.0-beta.4',
  unsupported: '2.1.0-unsupported.20180809',
  nightly: '4.0.0-nightly.20181010',
  'nightly-3-0-x': '3.0.0-nightly.20180904',
  'nightly-2-0-x': '2.0.8-nightly.20180820',
  '1-8-x': '1.8.8',
  '1-7-x': '1.7.16',
  '3-0-x': '3.0.16',
  '2-0-x': '2.0.18',
  'beta-4-0-x': '4.0.0-beta.11',
  'beta-3-1-x': '3.1.0-beta.5',
  '4-0-x': '4.0.8',
  '3-1-x': '3.1.12',
  'beta-5-0-x': '5.0.0-beta.9',
  '4-1-x': '4.1.5',
  '5-0-x': '5.0.10',
  '4-2-x': '4.2.10',
  'beta-6-0-x': '6.0.0-beta.15',
  '6-0-x': '6.0.10',
  HEAD: '3.1.13',
  'beta-7-0-x': '7.0.0-beta.4'
}

Electron のアップデート方法

% npm install electron@6.0.10 -g
 
/usr/local/bin/electron -> /usr/local/lib/node_modules/electron/cli.js
 
> electron@6.0.10 postinstall /usr/local/lib/node_modules/electron
> node install.js
 
+ electron@6.0.10
added 146 packages from 141 contributors in 5.884s