Home/Without a Mac/Can I build a macOS installer for an Electron app on Windows or Linux?

Can I build a macOS installer for an Electron app on Windows or Linux?

Updated · airankrush

The short answer

Short answer: per the official docs, Electron Forge builds only for the current operating system by default, and a dmg can only be generated on macOS. electron-builder states that macOS signing can only be done on macOS. To give users an installer that opens normally, you need a Mac.

Which steps require macOS

Where the official docs draw the line

  • Electron Forge: by default it builds only for the operating system it runs on. The description of the --platform flag is that you can generally only target platform X from platform X. The DMG maker's docs state a DMG can only be built on macOS machines, and the pkg maker likewise can only be used on macOS. The ZIP maker has no platform-specific dependencies and runs on any platform.
  • electron-builder: the multi-platform build docs open with "don't expect that you can build app for all platforms on one platform". When an app has native dependencies, it can only be compiled on the target platform unless the dependencies ship prebuilt binaries. The same page says macOS code signing works only on macOS and notes that this cannot be fixed.

What this means

  • Writing code, debugging the UI, and building Windows or Linux packages: keep these on your own machine.
  • The dmg for Mac users, and the signing and notarization needed so the system does not block it: these have to be done on macOS.
  • For projects that use native modules (Node extensions that need compiling), the macOS version must have its dependencies installed and compiled on macOS.

When you do not necessarily need to rent a Mac

Open-source projects, or projects whose repository is on GitHub, can build with CI that has macOS runners. electron-builder's GitHub Actions docs have a complete example. Renting a remote Mac with a visible desktop is only worth it when you need to install and verify by hand or investigate problems that only appear on macOS.

How to do it on a remote Mac

  1. Set up the environment on the remote Mac

    Reach the desktop through UU Remote or RustDesk and install Node.js and Git. Electron's code signing docs list installing Xcode as a prerequisite for macOS releases, so install it too if you plan to sign.

  2. Reinstall dependencies on the Mac

    After cloning the repository, run npm ci on this machine. Do not copy the node_modules directory over from Windows. Native modules need to be recompiled for macOS and this machine's architecture, and a copied directory contains binaries for another platform.

  3. Build with Electron Forge

    Install the DMG maker: npm install --save-dev @electron-forge/maker-dmg, add it to makers in the Forge config, and set options such as background and format if you like. Then run the project's make script (usually npm run make).

    If you need in-app auto-updates, the docs recommend configuring the ZIP maker as well: the auto-update mechanism on macOS uses the zip artifact, not the dmg.

  4. Or build with electron-builder

    npx electron-builder --mac

    Per the docs, the default macOS targets are dmg plus zip, and they state that even if you only distribute the dmg, turning off zip breaks auto-update. Specify the architecture with --x64, --arm64 or --universal. Optional settings include category (the app category) and minimumSystemVersion (the minimum OS version in Info.plist).

  5. Do a real install on the remote desktop

    Double-click the generated dmg, drag the app into the Applications folder, launch it, and walk through the main features. This is what CI cannot give you: the installer window layout, the system prompts on first launch, and how the menu bar and keyboard shortcuts behave on macOS all need a visible screen to confirm.

  6. Decide whether to sign

    For testing only on your own machine you can leave it unsigned for now. electron-builder's docs explain that setting mac.sign.identity to null skips signing. An unsigned app can still run locally on an Apple silicon Mac, but it has to be allowed under "System Settings → Privacy & Security". If you are sending it to anyone else, carry on to signing and notarization.

FAQ

What happens if I force the macOS platform when packaging on Windows?

Nothing official guarantees this route works. Forge's position is that you can generally only target a platform from that same platform. Even if an app directory or zip is produced in some cases, a dmg cannot be generated and the result cannot be signed or notarized, so the system blocks it after users download it. Projects with native modules also end up carrying binaries for the wrong platform.

Does a pure JavaScript project with no native modules still need a Mac?

At the code level nothing needs recompiling, but signing, notarization and the dmg can still only be done on macOS. As long as you intend to ship the app to ordinary users, there is no getting around it.

For this need, a remote Mac or an ordinary cloud server?

An ordinary cloud server runs Linux or Windows, and what you need here is macOS itself. For the difference between the two, see Mac mini vs VPS.

I want the remote Mac to build automatically

You can install the self-hosted runner program provided by your code platform on it, and it connects outbound to the platform to pick up jobs. For suitable scenarios and caveats, see using a rented Mac mini as an always-on build machine. For pricing and stock, see the plans page.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All no-Mac guides