Skip to content

feat: add ELECTRON_INSTALL_ env vars#49981

Merged
codebytere merged 5 commits into
electron:mainfrom
erickzhao:electron_install_env_var
Mar 12, 2026
Merged

feat: add ELECTRON_INSTALL_ env vars#49981
codebytere merged 5 commits into
electron:mainfrom
erickzhao:electron_install_env_var

Conversation

@erickzhao

Copy link
Copy Markdown
Member

Description of Change

Due to the binary no longer installing on npm install and us getting warnings from npm for setting unknown config values for npm install --platform win32 electron, here are two new env vars:

# before: pass npm config flag on install command
npm install --platform=mas electron --save-dev
# after: add env var when you first run the Electron command
npm install electron --save-dev
ELECTRON_INSTALL_PLATFORM=mas npx electron . --no

cc @electron/wg-api

Checklist

Release Notes

Notes: added ELECTRON_INSTALL_PLATFORM and ELECTRON_INSTALL_ARCH variables to install binaries from other platforms and architectures.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Feb 28, 2026
@erickzhao erickzhao added no-backport semver/minor backwards-compatible functionality labels Feb 28, 2026
@erickzhao erickzhao marked this pull request as ready for review March 2, 2026 19:00
@erickzhao erickzhao requested a review from a team as a code owner March 2, 2026 19:00

@VerteDinde VerteDinde left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, pending API approval 👍

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, but I think it would be helpful to list the arch and platforms we support.

Comment on lines +54 to +66
`arm64` machine), you can set the `ELECTRON_INSTALL_ARCH` environment variable:

```shell
npm install --arch=x64 electron
```sh
# Inside an npm script or with npx
ELECTRON_INSTALL_ARCH=x64 electron .
```

In addition to changing the architecture, you can also specify the platform
(e.g., `win32`, `linux`, etc.) using the `--platform` flag:

```shell
npm install --platform=win32 electron
```sh
# Inside an npm script or with npx
ELECTRON_INSTALL_PLATFORM=mas electron .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we explicitly list what arches and platforms we support?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends from version to version, but I added a little hint here: 1d3a211

Under the hood, @electron/get doesn't even define valid arch/platform combos in its types.

@erickzhao erickzhao requested a review from jkleinsc March 7, 2026 01:12
@erickzhao erickzhao added target/41-x-y PR should also be added to the "41-x-y" branch. no-backport and removed no-backport target/41-x-y PR should also be added to the "41-x-y" branch. labels Mar 9, 2026
Comment thread docs/tutorial/installation.md

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@codebytere codebytere left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@codebytere codebytere merged commit 313e501 into electron:main Mar 12, 2026
97 of 102 checks passed
@release-clerk

release-clerk Bot commented Mar 12, 2026

Copy link
Copy Markdown

Release Notes Persisted

added ELECTRON_INSTALL_PLATFORM and ELECTRON_INSTALL_ARCH variables to install binaries from other platforms and architectures.

officialasishkumar added a commit to officialasishkumar/electron that referenced this pull request Apr 13, 2026
The postinstall script resolves two things from the target platform:

1. Which artifact to download, via `downloadArtifact({ platform, ... })`.
   Since electron#49981, `platform` is derived from
   `ELECTRON_INSTALL_PLATFORM || npm_config_platform || process.platform`.
2. Which executable path to use for the `isInstalled()` cache check and
   for the `path.txt` marker written after extraction, via
   `getPlatformPath()`.

`getPlatformPath()` was not updated with the rest of that change and
still falls back to `npm_config_platform || os.platform()` only.

As a result, passing `ELECTRON_INSTALL_PLATFORM` (as documented in
`docs/tutorial/installation.md`) causes the two to disagree: the
download fetches the requested platform's zip, but `path.txt` and the
path sanity check are written against the host platform's executable
name. That in turn makes `isInstalled()` always return `false` on
subsequent runs (forcing redundant re-downloads) and makes the
executable path recorded in `path.txt` wrong for the artifact that
was actually extracted (e.g. `electron` written alongside a
`darwin`/`win32` build).

Check `ELECTRON_INSTALL_PLATFORM` first, matching the resolution used
for `downloadArtifact`.

Assisted-By: Claude Opus 4.6
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
officialasishkumar added a commit to officialasishkumar/electron that referenced this pull request Apr 16, 2026
The postinstall script resolves two things from the target platform:

1. Which artifact to download, via `downloadArtifact({ platform, ... })`.
   Since electron#49981, `platform` is derived from
   `ELECTRON_INSTALL_PLATFORM || npm_config_platform || process.platform`.
2. Which executable path to use for the `isInstalled()` cache check and
   for the `path.txt` marker written after extraction, via
   `getPlatformPath()`.

`getPlatformPath()` was not updated with the rest of that change and
still falls back to `npm_config_platform || os.platform()` only.

As a result, passing `ELECTRON_INSTALL_PLATFORM` (as documented in
`docs/tutorial/installation.md`) causes the two to disagree: the
download fetches the requested platform's zip, but `path.txt` and the
path sanity check are written against the host platform's executable
name. That in turn makes `isInstalled()` always return `false` on
subsequent runs (forcing redundant re-downloads) and makes the
executable path recorded in `path.txt` wrong for the artifact that
was actually extracted (e.g. `electron` written alongside a
`darwin`/`win32` build).

Check `ELECTRON_INSTALL_PLATFORM` first, matching the resolution used
for `downloadArtifact`.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
officialasishkumar added a commit to officialasishkumar/electron that referenced this pull request Apr 22, 2026
The postinstall script resolves two things from the target platform:

1. Which artifact to download, via `downloadArtifact({ platform, ... })`.
   Since electron#49981, `platform` is derived from
   `ELECTRON_INSTALL_PLATFORM || npm_config_platform || process.platform`.
2. Which executable path to use for the `isInstalled()` cache check and
   for the `path.txt` marker written after extraction, via
   `getPlatformPath()`.

`getPlatformPath()` was not updated with the rest of that change and
still falls back to `npm_config_platform || os.platform()` only.

As a result, passing `ELECTRON_INSTALL_PLATFORM` (as documented in
`docs/tutorial/installation.md`) causes the two to disagree: the
download fetches the requested platform's zip, but `path.txt` and the
path sanity check are written against the host platform's executable
name. That in turn makes `isInstalled()` always return `false` on
subsequent runs (forcing redundant re-downloads) and makes the
executable path recorded in `path.txt` wrong for the artifact that
was actually extracted (e.g. `electron` written alongside a
`darwin`/`win32` build).

Check `ELECTRON_INSTALL_PLATFORM` first, matching the resolution used
for `downloadArtifact`.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
jkleinsc pushed a commit that referenced this pull request Apr 28, 2026
The postinstall script resolves two things from the target platform:

1. Which artifact to download, via `downloadArtifact({ platform, ... })`.
   Since #49981, `platform` is derived from
   `ELECTRON_INSTALL_PLATFORM || npm_config_platform || process.platform`.
2. Which executable path to use for the `isInstalled()` cache check and
   for the `path.txt` marker written after extraction, via
   `getPlatformPath()`.

`getPlatformPath()` was not updated with the rest of that change and
still falls back to `npm_config_platform || os.platform()` only.

As a result, passing `ELECTRON_INSTALL_PLATFORM` (as documented in
`docs/tutorial/installation.md`) causes the two to disagree: the
download fetches the requested platform's zip, but `path.txt` and the
path sanity check are written against the host platform's executable
name. That in turn makes `isInstalled()` always return `false` on
subsequent runs (forcing redundant re-downloads) and makes the
executable path recorded in `path.txt` wrong for the artifact that
was actually extracted (e.g. `electron` written alongside a
`darwin`/`win32` build).

Check `ELECTRON_INSTALL_PLATFORM` first, matching the resolution used
for `downloadArtifact`.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
ckerr pushed a commit to erickzhao/ericktron that referenced this pull request Apr 30, 2026
…#51029)

The postinstall script resolves two things from the target platform:

1. Which artifact to download, via `downloadArtifact({ platform, ... })`.
   Since electron#49981, `platform` is derived from
   `ELECTRON_INSTALL_PLATFORM || npm_config_platform || process.platform`.
2. Which executable path to use for the `isInstalled()` cache check and
   for the `path.txt` marker written after extraction, via
   `getPlatformPath()`.

`getPlatformPath()` was not updated with the rest of that change and
still falls back to `npm_config_platform || os.platform()` only.

As a result, passing `ELECTRON_INSTALL_PLATFORM` (as documented in
`docs/tutorial/installation.md`) causes the two to disagree: the
download fetches the requested platform's zip, but `path.txt` and the
path sanity check are written against the host platform's executable
name. That in turn makes `isInstalled()` always return `false` on
subsequent runs (forcing redundant re-downloads) and makes the
executable path recorded in `path.txt` wrong for the artifact that
was actually extracted (e.g. `electron` written alongside a
`darwin`/`win32` build).

Check `ELECTRON_INSTALL_PLATFORM` first, matching the resolution used
for `downloadArtifact`.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
jkleinsc pushed a commit that referenced this pull request May 5, 2026
…51370)

* fix: honor `ELECTRON_INSTALL_PLATFORM` in `getPlatformPath` (#51029)

The postinstall script resolves two things from the target platform:

1. Which artifact to download, via `downloadArtifact({ platform, ... })`.
   Since #49981, `platform` is derived from
   `ELECTRON_INSTALL_PLATFORM || npm_config_platform || process.platform`.
2. Which executable path to use for the `isInstalled()` cache check and
   for the `path.txt` marker written after extraction, via
   `getPlatformPath()`.

`getPlatformPath()` was not updated with the rest of that change and
still falls back to `npm_config_platform || os.platform()` only.

As a result, passing `ELECTRON_INSTALL_PLATFORM` (as documented in
`docs/tutorial/installation.md`) causes the two to disagree: the
download fetches the requested platform's zip, but `path.txt` and the
path sanity check are written against the host platform's executable
name. That in turn makes `isInstalled()` always return `false` on
subsequent runs (forcing redundant re-downloads) and makes the
executable path recorded in `path.txt` wrong for the artifact that
was actually extracted (e.g. `electron` written alongside a
`darwin`/`win32` build).

Check `ELECTRON_INSTALL_PLATFORM` first, matching the resolution used
for `downloadArtifact`.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>

* run oxfmt

---------

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Co-authored-by: Asish Kumar <87874775+officialasishkumar@users.noreply.github.com>
Co-authored-by: Keeley Hammond <vertedinde@electronjs.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review/requested 🗳 new-pr 🌱 PR opened recently no-backport semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants