Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Install on Bash on Ubuntu on Windows (WSL) #260

Closed
ClementParis016 opened this issue May 29, 2017 · 13 comments
Closed

Install on Bash on Ubuntu on Windows (WSL) #260

ClementParis016 opened this issue May 29, 2017 · 13 comments

Comments

@ClementParis016
Copy link

After hours falling into a bunch of errors while trying to launch electron from WSL, I found the easiest way is to install electron on Windows then start it from WSL.

Steps:

  1. Make sure you have Node.js & npm installed on your Windows machine (you can remove them afterwards)
  2. Open cmd.exe, move to your project directory and run npm install electron --save-dev.
    This will install the Windows version of the prebuilt Electron binary instead of the Linux one, which would occur if you try to install from WSL. (This is the actual trick)
  3. Enter Bash on Ubuntu on Windows, move to your project directory then run ./node_modules/.bin/electron (or use an npm script) to launch your Electron app

Though, I'm not sure this is very convenient, it seems to work well.

I hope this will help people encoutering the same issue in the future!

@valorad
Copy link

valorad commented Jun 13, 2017

Thanks bro, you saved my day! :)
Currently haven't found any incompatibility yet (v1.7.3), but have to delete Linux version of electron and then install Windows version manually every time after package upgrades.

@ClementParis016
Copy link
Author

Indeed, you have to do it for every update, but anyway this is just a hack to work around an issue with WSL that should be resolved in next updates from Microsoft.

Still, I bet we could find a way to colocate Windows & Linux Electron binaries, I've seen Yarn has a sort of package aliasing system that could be a good starting point.

@PierBover
Copy link

Thanks for the tip. It worked for me too.

I had previously installed the linux version in bash and I had to delete the node_modules/electron folder and the install from Windows CMD.

@ClementParis016
Copy link
Author

Indeed, you could also npm uninstall electron then npm install electron

@dougmaitelli
Copy link

dougmaitelli commented Oct 9, 2017

You can use npm_config_platform environment variable to force Ubuntu Bash on Windows to install correct version:

"scripts": {
    "install-wsl": "export npm_config_platform=win32 && npm install",

Then run npm run install-wsl

@dougmaitelli
Copy link

Maybe even better to avoid problems with other packages:

"install-wsl": "npm install && npm uninstall electron && export npm_config_platform=win32 && npm install electron && unset npm_config_platform"

@ClementParis016
Copy link
Author

ClementParis016 commented Oct 9, 2017

I didn't know Electron was using the npm_config_platform var.
That's smart @dougmaitelli , have you tried it? It makes complete sense to tweak the platform var though.

@dougmaitelli
Copy link

dougmaitelli commented Oct 9, 2017

@ClementParis016 Yes, I just tried it before posting :)

Works perfectly, I did not know about this var before, was just looking into the install code from electron to find something similar then I found this var.

@daphen
Copy link

daphen commented Oct 26, 2017

Has it gotten any easier to use Electron in WSL since this was posted? This seems extremely tedious and I can't even get it to work. Granted with a vue-electron template, but still.

@ClementParis016
Copy link
Author

ClementParis016 commented Oct 26, 2017 via email

@daphen
Copy link

daphen commented Oct 26, 2017

Right, I didn't even think of that.
Thanks.

@DanMossa
Copy link

You are an amazing human being an deserve all the praise in the world

@thernstig
Copy link

Nothing new for now afaik. I guess it will always stay a bit hackish because WSL is not a standard OS for building desktop applications. The thing is we are executing a GUI on the Windows OS from a separated non-graphical OS (the Ubuntu subsystem) and only this is absolutely crazy when you think about it, so I can't see any way this could become more practical in the future. Le 26 oct. 2017 22:24, "David Karlsson" [email protected] a écrit :

Has it gotten any easier to use Electron in WSL since this was posted? This seems extremely tedious and I can't even get it to work. Granted with a vue-electron template, but still. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#260 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AFV5l7bRGDX9DsYdvV4us0SzgIAU4pg8ks5swOp1gaJpZM4NppYx .

I found this a bit funny now that this is actually happening. WSL2 will be able to run Linux GUI apps in Windows. https://devblogs.microsoft.com/commandline/the-windows-subsystem-for-linux-build-2020-summary/#wsl-gui

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants