electron-updater package, which allows your application to automatically check for and install new versions. This guide covers the complete setup process.
How Auto-Updates Work
The auto-update process follows these steps:- Configure the package to build release metadata (
latest.yml) - Electron builder uploads release targets and metadata files to the configured target
- Your Electron application queries the publish server for new releases
Auto-Updatable Targets
The following build targets support auto-updates out of the box:- macOS: DMG
- Linux: AppImage, DEB, Pacman (beta), and RPM
- Windows: NSIS
- Squirrel.Windows is not supported. Use the default NSIS target instead. You can migrate to NSIS.
- For macOS, the
ziptarget is required for Squirrel.Mac to createlatest-mac.yml. The default target isdmg+zip, so no explicit configuration is needed.
Differences from Built-in autoUpdater
Theelectron-updater package offers several advantages over Electron’s built-in auto-updater:
- Linux support in addition to macOS and Windows
- Code signature validation on both macOS and Windows
- Automatic metadata generation - all required metadata files and artifacts are produced and published automatically
- Download progress and staged rollouts supported on all platforms
- Multiple providers supported out of the box:
- GitHub Releases
- Amazon S3
- DigitalOcean Spaces
- Keygen
- Generic HTTP(s) server
- Simple integration - only 2 lines of code required
Quick Setup Guide
1. Install electron-updater
Install electron-updater as an app dependency:2. Configure Publish Options
Configure thepublish options in your electron-builder config depending on where you want to host your release files.
3. Build Your Application
Build your application and verify that the build directory contains the metadata.yml files next to the built application. For most publish targets, the build step will also upload the files automatically (except for generic server option, where you must upload manually).
4. Import autoUpdater
UseautoUpdater from electron-updater instead of electron:
5. Check for Updates
CallautoUpdater.checkForUpdatesAndNotify() for simple automatic updates, or implement custom event handlers for more control.
Basic Implementation
Simple Auto-Update with Notifications
Custom Implementation with Event Handlers
For more control over the update process, listen to specific events:Advanced Configuration
Custom Options with Direct Instantiation
For more control over the updater configuration (e.g., request headers for authorization):Staged Rollouts
Staged rollouts allow you to distribute updates to a subset of users. Control this by editing yourlatest.yml / latest-mac.yml file:
API Reference
Properties
Whether to automatically download an update when it is found.
Whether to automatically install a downloaded update on app quit (if
quitAndInstall was not called before).Whether to run the app after finish install when the installer is NOT in silent mode.
GitHub provider only. Whether to allow update to pre-release versions. Defaults to
true if application version contains prerelease components (e.g. 0.12.1-alpha.1), otherwise false.If true, downgrade will be allowed (allowDowngrade will be set to true).Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel).Taken into account only if channel differs (pre-release version component in terms of semantic versioning).
NSIS only Disable differential downloads and always perform full download of installer.
Allows developer to force the updater to work in “dev” mode, looking for “dev-app-update.yml” instead of “app-update.yml”.
- Dev:
path.join(this.app.getAppPath(), "dev-app-update.yml") - Prod:
path.join(process.resourcesPath!, "app-update.yml")
Events
TheautoUpdater object emits the following events:
error
errorError
checking-for-update
Emitted when checking if an update has started.
update-available
infoUpdateInfo
autoDownload is true.
update-not-available
infoUpdateInfo
download-progress
progressProgressInfobytesPerSecond- Download speed in bytes per secondpercent- Progress percentagetotal- Total bytestransferred- Transferred bytes
update-downloaded
infoUpdateInfo
Methods
checkForUpdates()
Asks the server whether there is an update.
Returns: Promise<UpdateCheckResult | null> - Returns null if the updater is disabled, otherwise info about the latest version.
checkForUpdatesAndNotify()
Checks for updates and shows a system notification when an update is downloaded.
Returns: Promise<UpdateCheckResult | null>
downloadUpdate(cancellationToken?)
Start downloading update manually. Use this method if autoDownload option is set to false.
Parameters:
cancellationToken- Optional cancellation token
Promise<Array<string>> - Paths to downloaded files.
quitAndInstall(isSilent?, isForceRunAfter?)
Restarts the app and installs the update after it has been downloaded. Should only be called after update-downloaded has been emitted.
Parameters:
isSilent(boolean) - Windows-only Runs the installer in silent mode. Defaults tofalse.isForceRunAfter(boolean) - Run the app after finish even on silent install. Not applicable for macOS. Ignored ifisSilentis set tofalse.
autoUpdater.quitAndInstall() will close all application windows first and only emit before-quit event on app after that. This is different from the normal quit event sequence.Examples
- Complete example showing how to use electron-updater
- Encapsulated manual update via menu
Private GitHub Update Repo
You can use a private repository for updates with electron-updater by setting theGH_TOKEN environment variable (on user machine) and private option. If GH_TOKEN is set, electron-updater will use the GitHub API for updates.
The GitHub API currently has a rate limit of 5000 requests per user per hour. An update check uses up to 3 requests per check.
Compatibility
Generated metadata files format changes from time to time, but compatibility is preserved up to version 1. For new projects, setelectronUpdaterCompatibility to the current latest format version (>= 2.16).
Option electronUpdaterCompatibility sets the electron-updater compatibility semver range. Can be specified per platform.
Examples: >= 2.16, >=1.0.0. Defaults to >=2.15
1.0.0- latest-mac.json2.15.0- path2.16.0- files
Generated Files
latest.yml (or latest-mac.yml for macOS, or latest-linux.yml for Linux) will be generated and uploaded for all providers except bintray.