Skip to content

Development Environment Setup: Windows

AdamOFN edited this page Jan 19, 2023 · 1 revision

Intro

This guide will help you set up a development environment for OFN on Windows 10 or 11. It uses the Windows Subsystem for Linux, which uses virtualisation to run a Linux distribution (mostly) seamlessly within Windows. It is similar to a virtual machine, but with lower system resource usage and more integrated with the host OS.

Step 1. Update WSL and install Ubuntu

WSL is usually included with Windows, but may be out of date. Older versions didn't have the ability to use systemd, the system that controls services in Ubuntu. To update WSL, open a command prompt as administrator and enter:

wsl --update

If this command fails, WSL may not be installed. You can install the current version from the Microsoft App Store.

Install the most recent LTS version of Ubuntu with

wsl --install -d Ubuntu

Step 2. Configure Ubuntu to use systemd

Open Ubuntu from your start menu. The first time you open it, you will need to configure a username and password. To configure Ubuntu to use systemd, enter the following in the Ubuntu shell

echo '[boot]' | sudo tee -a /etc/wsl.conf
echo 'systemd=true' | sudo tee -a /etc/wsl.conf

You will then need to restart WSL. From a command prompt as administrator:

wsl --shutdown

Then restart Ubuntu from the start menu.

Step 3. Continue with the Ubuntu instructions

You can now follow the instructions in the guide for Ubuntu from the Ubuntu shell. Note that you can install (some) GUI apps in the Ubuntu shell, including Chromium. The Ubuntu shell has its own IP address (different to the host Windows IP address) which can change, so it may be more convenient to run a copy of Chromium from Ubuntu for testing than to try to connect a Windows-installed browser to the dev server. Start Chromium with chromium &.

You can access the Ubuntu file system from Windows at \\wsl$\Ubuntu

Debugging on WSL with RubyMine

If you have RubyMine installed on your Windows host, you can debug projects installed on WSL. Start RubyMine and open the project from \\wsl$\Ubuntu\home\YOUR_USERNAME\openfoodnetwork. From File > Settings, navigate to Languages & Frameworks > Ruby SDK and Gems. Click the + icon and pick Remote Interpreter or Version Manager. Select WSL, then pick Ubuntu. The Ruby or version manager path is at /home/YOUR_USERNAME/.rbenv/bin/rbenv. Click OK then pick the correct version of Ruby from the list (3.0.3 at the time of writing). Lastly click the radio button next to the Remote-rbenv option you just created and then OK.

That loads the project correctly in RubyMine. To configure debugging, from Run > Edit Configurations... click + to add a new configuration. Choose Gem Command and set the following options:

  • Gem name: foreman
  • Executable name: foreman
  • Arguments: start
  • Environment variables: NODE_OPTIONS=--openssl-legacy-provider

You can name the configuration whatever you like. Click OK. You can now run the debug configuration and it will start the dev server on Ubuntu in WSL.

Clone this wiki locally