@@ -9,6 +9,7 @@ title: Installing Cypress
99- How to install Cypress via ` npm `
1010- How to install Cypress via direct download
1111- How to version and run Cypress via ` package.json `
12+ - How to run Cypress on ` wsl2 ` in windows
1213
1314</Alert >
1415
@@ -515,3 +516,76 @@ Notes on pre-releases:
515516 release over a pre-release - if you have a pre-release of Cypress vX.Y.Z
516517 installed, the official release of Cypress vX.Y.Z will not install until you
517518 do `cypress cache clear`.
519+
520+ # ## Windows Subsystem for Linux
521+
522+ # ### WSL2
523+
524+ First, install the prerequisite packages using the command that relates to your
525+ linux distribution ([Ubuntu/Debian](#Ubuntu-Debian) or [CentOS](#CentOS)).
526+
527+ We need to have an [X-server](https://en.wikipedia.org/wiki/X.Org_Server) to
528+ display the Cypress UI from the linux subsystem. There are a variety of
529+ X-servers available, here we are going to use VcXsrv, you can use any other
530+ similar tool.
531+
532+ Download [VcXsrv](https://sourceforge.net/projects/vcxsrv/) and install. You can
533+ set the settings to your preference ("Multiple windows" and "Start no client"
534+ are recommended), but on the page that lets you enable extra settings, be sure
535+ to select "Disable access control" which is required as WSL2 has its own IP
536+ address, which changes often.
537+
538+ <DocsImage src="/img/guides/vcxsrv-extra-settings.png" alt="Disable access control in vcxsrv" ></DocsImage>
539+
540+ In your `.bashrc` (or equivalent such as `.zshrc`) set the `DISPLAY` environment
541+ variable.
542+
543+ ` ` ` shell
544+ # set DISPLAY variable to the IP automatically assigned to WSL2
545+ export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
546+ ` ` `
547+
548+ To confirm `DISPLAY` variable has been set, print it out in the terminal. You
549+ may need to restart your terminal to see this change.
550+
551+ ` ` ` shell
552+ echo $DISPLAY
553+ # something like 172.17.224.1:0.0
554+ ` ` `
555+
556+ The VcXsrv GUI uses [D-Bus](https://www.freedesktop.org/wiki/Software/dbus/) to
557+ internally communicate. After the `export DISPLAY` line in your `.bashrc`, add
558+ the following :
559+
560+ ` ` ` shell
561+ sudo /etc/init.d/dbus start &> /dev/null
562+ ` ` `
563+
564+ Now your user needs to be granted access to run `sudo dbus` without needing to
565+ enter a password. To do so, use the `visido` command :
566+
567+ ` ` ` shell
568+ sudo visudo -f /etc/sudoers.d/dbus
569+ ` ` `
570+
571+ In the editor that launches, add the following line, replacing `<your_username>`
572+ with your username (you can use the `whoami` command to print your username if
573+ you don't know it).
574+
575+ ```
576+ <your_username> ALL = (root) NOPASSWD: /etc/init.d/dbus
577+ ```
578+
579+ Go to Control Panel > System and Security > Windows Defender Firewall > Inbound
580+ Rules > New Rule.
581+
582+ <DocsImage src="/img/guides/windows-firewall-disable-vcxsrv.png" alt="Add rule to allow connections for vcxsrv" ></DocsImage>
583+
584+ Select Program and click on next. On the This program path, browse and select
585+ path to VcxSrv. On the next page select allow the connection and click next. On
586+ the next page, select all three options (Domain, Private, Public).
587+
588+ <DocsImage src="/img/guides/rule-application-selection.png" alt="Select inbound rule application cases for vcxsrv" ></DocsImage>
589+
590+ Give the rule a suitable name and description and click finish. WSL2 should now
591+ be able to open a GUI from shell.
0 commit comments