2021-08-16 12:12:34 +00:00
|
|
|
# Advanced Installation Instructions
|
2017-08-08 17:18:22 +00:00
|
|
|
|
2018-02-19 23:53:29 +00:00
|
|
|
To install prebuilt Electron binaries, use [`npm`][npm].
|
2017-08-08 17:18:22 +00:00
|
|
|
The preferred method is to install Electron as a development dependency in your
|
|
|
|
app:
|
|
|
|
|
|
|
|
```sh
|
2017-10-04 19:41:12 +00:00
|
|
|
npm install electron --save-dev
|
2017-08-08 17:18:22 +00:00
|
|
|
```
|
|
|
|
|
2018-02-19 23:53:29 +00:00
|
|
|
See the [Electron versioning doc][versioning] for info on how to
|
|
|
|
manage Electron versions in your apps.
|
2017-08-08 17:18:22 +00:00
|
|
|
|
2021-05-03 14:25:34 +00:00
|
|
|
## Running Electron ad-hoc
|
2017-08-08 17:18:22 +00:00
|
|
|
|
2021-05-03 14:25:34 +00:00
|
|
|
If you're in a pinch and would prefer to not use `npm install` in your local
|
|
|
|
project, you can also run Electron ad-hoc using the [`npx`][npx] command runner
|
|
|
|
bundled with `npm`:
|
2017-08-08 17:18:22 +00:00
|
|
|
|
|
|
|
```sh
|
2021-05-03 14:25:34 +00:00
|
|
|
npx electron .
|
2017-08-08 17:18:22 +00:00
|
|
|
```
|
|
|
|
|
2021-05-03 14:25:34 +00:00
|
|
|
The above command will run the current working directory with Electron. Note that
|
|
|
|
any dependencies in your app will not be installed.
|
|
|
|
|
2017-08-08 17:18:22 +00:00
|
|
|
## Customization
|
|
|
|
|
|
|
|
If you want to change the architecture that is downloaded (e.g., `ia32` on an
|
|
|
|
`x64` machine), you can use the `--arch` flag with npm install or set the
|
|
|
|
`npm_config_arch` environment variable:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
npm install --arch=ia32 electron
|
|
|
|
```
|
|
|
|
|
2018-01-19 21:33:36 +00:00
|
|
|
In addition to changing the architecture, you can also specify the platform
|
2017-08-08 22:22:52 +00:00
|
|
|
(e.g., `win32`, `linux`, etc.) using the `--platform` flag:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
npm install --platform=win32 electron
|
|
|
|
```
|
|
|
|
|
2017-08-08 17:18:22 +00:00
|
|
|
## Proxies
|
|
|
|
|
2019-11-05 21:40:43 +00:00
|
|
|
If you need to use an HTTP proxy, you need to set the `ELECTRON_GET_USE_PROXY` variable to any
|
|
|
|
value, plus additional environment variables depending on your host system's Node version:
|
|
|
|
|
|
|
|
* [Node 10 and above][proxy-env-10]
|
|
|
|
* [Before Node 10][proxy-env]
|
2017-08-08 17:18:22 +00:00
|
|
|
|
2018-01-19 21:33:36 +00:00
|
|
|
## Custom Mirrors and Caches
|
2020-11-05 22:12:43 +00:00
|
|
|
|
2018-02-19 23:53:29 +00:00
|
|
|
During installation, the `electron` module will call out to
|
2019-11-05 21:40:43 +00:00
|
|
|
[`@electron/get`][electron-get] to download prebuilt binaries of
|
2018-02-19 23:53:29 +00:00
|
|
|
Electron for your platform. It will do so by contacting GitHub's
|
2018-01-19 21:33:36 +00:00
|
|
|
release download page (`https://github.com/electron/electron/releases/tag/v$VERSION`,
|
|
|
|
where `$VERSION` is the exact version of Electron).
|
|
|
|
|
|
|
|
If you are unable to access GitHub or you need to provide a custom build, you
|
|
|
|
can do so by either providing a mirror or an existing cache directory.
|
|
|
|
|
|
|
|
#### Mirror
|
2020-11-05 22:12:43 +00:00
|
|
|
|
2018-01-19 21:33:36 +00:00
|
|
|
You can use environment variables to override the base URL, the path at which to
|
2020-03-04 13:44:04 +00:00
|
|
|
look for Electron binaries, and the binary filename. The URL used by `@electron/get`
|
2018-01-19 21:33:36 +00:00
|
|
|
is composed as follows:
|
|
|
|
|
2023-06-05 07:26:26 +00:00
|
|
|
```javascript @ts-nocheck
|
2018-01-19 21:33:36 +00:00
|
|
|
url = ELECTRON_MIRROR + ELECTRON_CUSTOM_DIR + '/' + ELECTRON_CUSTOM_FILENAME
|
|
|
|
```
|
|
|
|
|
2020-03-04 13:44:04 +00:00
|
|
|
For instance, to use the China CDN mirror:
|
2018-01-19 21:33:36 +00:00
|
|
|
|
2020-03-04 13:44:04 +00:00
|
|
|
```shell
|
2021-12-06 02:28:41 +00:00
|
|
|
ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
|
2018-01-19 21:33:36 +00:00
|
|
|
```
|
|
|
|
|
2020-03-04 13:44:04 +00:00
|
|
|
By default, `ELECTRON_CUSTOM_DIR` is set to `v$VERSION`. To change the format,
|
|
|
|
use the `{{ version }}` placeholder. For example, `version-{{ version }}`
|
|
|
|
resolves to `version-5.0.0`, `{{ version }}` resolves to `5.0.0`, and
|
|
|
|
`v{{ version }}` is equivalent to the default. As a more concrete example, to
|
|
|
|
use the China non-CDN mirror:
|
|
|
|
|
|
|
|
```shell
|
2021-12-06 02:28:41 +00:00
|
|
|
ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
|
2020-03-04 13:44:04 +00:00
|
|
|
ELECTRON_CUSTOM_DIR="{{ version }}"
|
|
|
|
```
|
|
|
|
|
|
|
|
The above configuration will download from URLs such as
|
2021-12-06 02:28:41 +00:00
|
|
|
`https://npmmirror.com/mirrors/electron/8.0.0/electron-v8.0.0-linux-x64.zip`.
|
2020-03-04 13:44:04 +00:00
|
|
|
|
2021-08-19 18:26:17 +00:00
|
|
|
If your mirror serves artifacts with different checksums to the official
|
2021-12-13 06:42:43 +00:00
|
|
|
Electron release you may have to set `electron_use_remote_checksums=1` to
|
2021-08-19 18:26:17 +00:00
|
|
|
force Electron to use the remote `SHASUMS256.txt` file to verify the checksum
|
|
|
|
instead of the embedded checksums.
|
|
|
|
|
2018-01-19 21:33:36 +00:00
|
|
|
#### Cache
|
2020-11-05 22:12:43 +00:00
|
|
|
|
2019-12-16 16:16:55 +00:00
|
|
|
Alternatively, you can override the local cache. `@electron/get` will cache
|
2018-01-19 21:33:36 +00:00
|
|
|
downloaded binaries in a local directory to not stress your network. You can use
|
|
|
|
that cache folder to provide custom builds of Electron or to avoid making contact
|
|
|
|
with the network at all.
|
|
|
|
|
|
|
|
* Linux: `$XDG_CACHE_HOME` or `~/.cache/electron/`
|
2020-03-31 04:06:25 +00:00
|
|
|
* macOS: `~/Library/Caches/electron/`
|
2018-01-19 21:33:36 +00:00
|
|
|
* Windows: `$LOCALAPPDATA/electron/Cache` or `~/AppData/Local/electron/Cache/`
|
|
|
|
|
|
|
|
On environments that have been using older versions of Electron, you might find the
|
|
|
|
cache also in `~/.electron`.
|
|
|
|
|
2019-12-02 18:12:51 +00:00
|
|
|
You can also override the local cache location by providing a `electron_config_cache`
|
2018-01-19 21:33:36 +00:00
|
|
|
environment variable.
|
|
|
|
|
2021-11-17 15:16:08 +00:00
|
|
|
The cache contains the version's official zip file as well as a checksum, and is stored as
|
|
|
|
`[checksum]/[filename]`. A typical cache might look like this:
|
2018-01-19 21:33:36 +00:00
|
|
|
|
|
|
|
```sh
|
2021-11-17 15:16:08 +00:00
|
|
|
├── a91b089b5dc5b1279966511344b805ec84869b6cd60af44f800b363bba25b915
|
|
|
|
│ └── electron-v15.3.1-darwin-x64.zip
|
2018-01-19 21:33:36 +00:00
|
|
|
```
|
|
|
|
|
2019-05-03 17:17:15 +00:00
|
|
|
## Skip binary download
|
2020-11-05 22:12:43 +00:00
|
|
|
|
2021-06-17 06:34:08 +00:00
|
|
|
Under the hood, Electron's JavaScript API binds to a binary that contains its
|
|
|
|
implementations. Because this binary is crucial to the function of any Electron app,
|
|
|
|
it is downloaded by default in the `postinstall` step every time you install `electron`
|
|
|
|
from the npm registry.
|
|
|
|
|
|
|
|
However, if you want to install your project's dependencies but don't need to use
|
|
|
|
Electron functionality, you can set the `ELECTRON_SKIP_BINARY_DOWNLOAD` environment
|
|
|
|
variable to prevent the binary from being downloaded. For instance, this feature can
|
|
|
|
be useful in continuous integration environments when running unit tests that mock
|
|
|
|
out the `electron` module.
|
|
|
|
|
|
|
|
```sh npm2yarn
|
2019-05-03 17:17:15 +00:00
|
|
|
ELECTRON_SKIP_BINARY_DOWNLOAD=1 npm install
|
|
|
|
```
|
|
|
|
|
2017-08-08 17:18:22 +00:00
|
|
|
## Troubleshooting
|
|
|
|
|
2018-01-19 21:33:36 +00:00
|
|
|
When running `npm install electron`, some users occasionally encounter
|
2017-08-08 17:18:22 +00:00
|
|
|
installation errors.
|
|
|
|
|
2018-01-19 21:33:36 +00:00
|
|
|
In almost all cases, these errors are the result of network problems and not
|
|
|
|
actual issues with the `electron` npm package. Errors like `ELIFECYCLE`,
|
|
|
|
`EAI_AGAIN`, `ECONNRESET`, and `ETIMEDOUT` are all indications of such
|
|
|
|
network problems. The best resolution is to try switching networks, or
|
2018-05-08 05:16:09 +00:00
|
|
|
wait a bit and try installing again.
|
2017-08-08 17:18:22 +00:00
|
|
|
|
2018-01-19 21:33:36 +00:00
|
|
|
You can also attempt to download Electron directly from
|
2018-02-19 23:53:29 +00:00
|
|
|
[electron/electron/releases][releases]
|
2017-08-08 17:18:22 +00:00
|
|
|
if installing via `npm` is failing.
|
|
|
|
|
2018-01-19 21:33:36 +00:00
|
|
|
If installation fails with an `EACCESS` error you may need to
|
2018-02-19 23:53:29 +00:00
|
|
|
[fix your npm permissions][npm-permissions].
|
2017-08-08 22:22:52 +00:00
|
|
|
|
2018-02-19 23:53:29 +00:00
|
|
|
If the above error persists, the [unsafe-perm][unsafe-perm] flag may need to be
|
|
|
|
set to true:
|
2017-08-08 22:22:52 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
sudo npm install electron --unsafe-perm=true
|
|
|
|
```
|
|
|
|
|
2018-02-19 23:53:29 +00:00
|
|
|
On slower networks, it may be advisable to use the `--verbose` flag in order to
|
|
|
|
show download progress:
|
2017-08-08 22:22:52 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
npm install --verbose electron
|
|
|
|
```
|
|
|
|
|
2017-08-08 17:18:22 +00:00
|
|
|
If you need to force a re-download of the asset and the SHASUM file set the
|
2018-02-13 05:18:27 +00:00
|
|
|
`force_no_cache` environment variable to `true`.
|
2018-02-19 23:53:29 +00:00
|
|
|
|
|
|
|
[npm]: https://docs.npmjs.com
|
|
|
|
[versioning]: ./electron-versioning.md
|
2021-05-03 14:25:34 +00:00
|
|
|
[npx]: https://docs.npmjs.com/cli/v7/commands/npx
|
2018-02-19 23:53:29 +00:00
|
|
|
[releases]: https://github.com/electron/electron/releases
|
2019-11-05 21:40:43 +00:00
|
|
|
[proxy-env-10]: https://github.com/gajus/global-agent/blob/v2.1.5/README.md#environment-variables
|
|
|
|
[proxy-env]: https://github.com/np-maintain/global-tunnel/blob/v2.7.1/README.md#auto-config
|
|
|
|
[electron-get]: https://github.com/electron/get
|
2018-02-19 23:53:29 +00:00
|
|
|
[npm-permissions]: https://docs.npmjs.com/getting-started/fixing-npm-permissions
|
2018-05-08 05:16:09 +00:00
|
|
|
[unsafe-perm]: https://docs.npmjs.com/misc/config#unsafe-perm
|