Setting Up WSL2 for Expo Go: First steps for React Native developers

Introduction
Welcome to our comprehensive guide on setting up WSL2 for React Native using Expo. This setup is crucial for developers who want to streamline their mobile app development and testing processes. By following this guide, you will configure your Windows Subsystem for Linux to efficiently use Expo Go without using Tunnel or Hyper-V Configuration, enhancing your development workflow.
Requirements
- SO >= Windows 11 Pro (22H2)
- WSL2
Configuring WSL2
The first step in optimizing WSL2 for Expo Go involves adjusting the networking configuration. This is crucial for ensuring that your mobile device can communicate with WSL2 when using Expo Go. To achieve this, you need to add the "networkingMode=mirrored" setting to your .wslconfig file in Windows.
- Open your .wslconfig file located in your user directory.
- Add the following line to the file:
[wsl2]networkingMode=mirrored
This setting mirrors the network configuration of your host machine, which simplifies the network communication between WSL2 and other devices in your network, such as your mobile phone running Expo Go.
Allowing Incoming Requests
To allow incoming requests, particularly from your mobile device using Expo Go, you need to adjust the firewall settings. This involves using a specific command in PowerShell run as an administrator.
- Open PowerShell as an administrator.
- Execute the following commands:
Set-NetFirewallHyperVVMSetting -Name ‘{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}’ -DefaultOutboundAction Allow
Set-NetFirewallHyperVVMSetting -Name ‘{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}’ -DefaultInboundAction Allow
This command configures the firewall to allow incoming connections to the Hyper-V virtual machines, which includes your WSL2 environment. This is essential for Expo Go to interact with applications running inside WSL2.
Conclusion
By following these steps, you will have configured your WSL2 environment to work seamlessly with Expo Go, allowing for a more integrated and efficient mobile development experience. This setup not only enhances your development workflow but also ensures that you can test your applications in a more realistic environment.
Remember to restart your WSL2 instance after making these changes to apply them effectively.
Happy Hacking!