After struggling with this for few days I decided to write this guide, hopefully it will help someone.
I have to give credit to the guy who wrote made the initial guide. I updated his code to work with electron 10.1.5.
Here is the link to Matt Haggard and his electron-updater-example
This repo contains the bare minimum code to have an auto-updating Electron app using electron-updater
.
Clone the repo cd into project folder and execute these commands.
npm install
npm start
If everything went well, you can continue with this guide.
-
For macOS, you will need a code-signing certificate. Install Xcode (from the App Store), then follow these instructions to make sure you have a "Mac Developer" certificate. If you'd like to export the certificate (for automated building, for instance) you can. You would then follow these instructions.
-
On Windows, you can generate self-signed certificate for testing and development purposes. This certificate is required for electron-updater to work properly. You can generate this certificate by following steps below: Open Windows PowerShell with administrative privileges and execute these commands:
$rootCert = New-SelfSignedCertificate -DnsName "martin" -Type CodeSigningCert -CertStoreLocation "C:\projects\nsis-test\certs\" [System.Security.SecureString]$rootcertPassword = ConvertTo-SecureString -String "some_password" -Force -AsPlainText [String]$rootCertPath = Join-Path -Path 'cert:\CurrentUser\My\' -ChildPath "$($rootcert.Thumbprint)" [String]$rootCertPath = Join-Path -Path 'cert:\LocalMachine\My\' -ChildPath "$($rootcert.Thumbprint)" Export-PfxCertificate -Cert $rootCertPath -FilePath 'RootCA.pfx' -Password $rootcertPassword Export-Certificate -Cert $rootCertPath -FilePath 'RootCA.crt'
After successful creation of certificate files, make sure that they are in correct location. Open Certificate Manager by clicking on the Start button, type certmgr.msc in the search field and press Enter key.
If your newly created certificate is not in Trusted Root Certification Authorities certificate folder, drag and drop it from Personal. Otherwise automatic updates will not work.
Next, open package.json in your favorite text editor and modify these three lines.
"publisherName": "Some Company", // when using self signed certs, enter a random string "certificateFile": "./certs/some_file.pfx", "certificatePassword": "some_password"
Note: self-signed certificate can only be used for testing purposes. You can get more help on these websites:
When you are done with code signing mess, it's time for building and testing. In package.json under scripts.dist key you can set your desired os. See the example below.
- -m - Mac OS - I lost my microfiber cloth, it's gonna cost me a fortune
- -w - Windows - Obscure, gimmicky gaming platform with built in spyware
- -l - Linux - OS for the people
"scripts": {
"dist": "electron-builder -mwl"
}
After configuring dist key for your OS, run the command below.
npm run dist
When npm run dist finishes with the building process, open /dist folder and install the app on your system. After successful install, bump the version in package.json and and run the "npm run dist" command once again. When done, copy paste the contents of /dist folder to /wwwroot folder and run "npm run serve". Open the previous version that you installed on your system and voilà :)!