Building extensions for WooCommerce involves development tools that have historically not catered to developers working in Windows environments. Thankfully, due to new technologies such as virtualization, Windows developers can create fully functional development environments just like the ones running natively on Linux and Mac operating systems. The steps below are intended to walk through the process of setting up a Linux subsystem on a Windows machine where you can build extensions using the instructions in the WooCommerce Extension Developer Guide.
Note: These instructions utilize the Windows Subsystem for Linux feature, which is only available in Windows 10 and later.
Windows Subsystem for Linux (WSL) is a lightweight virtualization platform that lets you run Linux distributions directly inside Windows without the need for a bulky traditional virtual machine. For the most up-to-date setup instructions, please take a look at the Windows Subsystem for Linux Installation Guide for Windows 10 chapter of the WSL Documentation.
Members of the Windows Insiders Program, can take advantage of a simplified installation process. Once you have signed up for the program, you need to install a preview build of Windows (OS Build 20262 or higher) and then open up a command prompt with administrator privileges and type the following command:
This will perform the following actions for you:
- Enable the optional WSL and Virtual Machine Platform components
- Download and install the latest Linux kernel
- Set WSL 2 as the default
- Download and install a Linux distribution
Once the installation has finished, restart your machine. Your Linux subsystem environment will give you easier access to many common command line utilities nececessary for development, such as Git, cURL, and others.
Once WSL has been activated, you should have access to an Ubuntu installation as an app in your machine’s Start menu. To start the environment, click the app’s icon and Windows will launch a new terminal shell.
Installing NVM and Node
Once you have an Ubuntu shell running on your machine, you should install NVM, which helps you manage multiple installations of Node.js in your environment.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
This will download and install NVM. Once the installation is complete, use NVM to install the latest stable LTS release of Node:
nvm install --lts
For the most up-to-date instructions, please take a look at Install Node.js on Windows Subsystem for Linux in the Microsoft Developer Documentation.
The easiest way to use Docker on a Windows machine, is to install the Docker Desktop client. It includes Docker Engine, the Docker CLI client, Docker Compose, and other utilities that are useful for development.
Because you will be using Docker in conjunction with WSL on your machine, be sure to activate the WSL integration for your installed Linux distribution:
- Navigate to
Settings -> Generaland make sure that “Use the WSL 2 based engine” is checked.
- Navigate to
Settings -> Resources -> WSL Integrationand make sure the integration is enabled for the Ubuntu environment you set up earlier.
You can test to make sure the Docker is working properly by opening up your Ubunutu terminal and running the following commands:
docker --version docker run hello-world
For the most up-to-date instructions about using Docker with WSL, please take see Get started with Docker remote containers on WSL 2 in the Microsoft Developer Documentation.
Once you have a running Linux environment, you can follow the guidance in the WooCommerce Extension Developer Guide to install further dependencies and finish configuring your development environment. For instance, you’ll still need to install PHP and Composer inside your Ubuntu subsystem, and you may want to take advantage of the Docker-based environment management tool
wp-env, which lets you create a containerized WordPress development environment with a few terminal commands.