Fragmented memories that are hard to recall
Q&A

Question
How to use Linux tools in a Windows environment
Answer
If you are a developer on Windows, you must have experienced the pain of being in a “dilemma”: needing Linux tools but being locked into the Windows ecosystem. π₯οΈ
Of course, you can use a virtual machine or dual-boot system, but you will encounter various troubles: slow speed, poor experience, and many issues, often making it not worth the effort. π€
At this point, WSL (Windows Subsystem for Linux) comes into play. Imagine running a complete Linux environment natively on your Windows machineβno virtual machine, no extra configuration, just the full functionality of Linux without leaving your current work environment, and itβs a comprehensive solution. With WSL, you can enjoy the best of both Windows and Linux: flexible, powerful, and efficient.
What is WSL? π€

Windows Subsystem for Linux (WSL) is a revolutionary feature of Windows that allows you to run a complete Linux environment directly on your Windows machine without a separate virtual machine or dual-boot system. π§β¨ Whether you are developing software, testing servers, or need to use Linux command-line tools, WSL can greatly simplify your workflow. The best part is that you can have the powerful features of both Windows and Linux, all integrated into one system. π
WSL 1 is implemented through a compatibility layer that converts Linux system calls into Windows system calls. While it works, it feels a bit like a “black technology” solution, as it cannot run a complete Linux kernel, thus having certain limitations in performance and some specific Linux features.
WSL 2 is a groundbreaking upgrade. Microsoft introduced WSL 2 by bringing in a real Linux kernel (through virtualization technology), enhancing performance, system compatibility, and providing a more authentic Linux experience. π₯
WSL 2 runs a lightweight virtual machine (VM), with each Linux distribution running as an isolated container. The key difference is that each Linux distribution has its own independent environment, making it more secure and efficient than WSL 1.
Distributions in WSL 2 share some content (such as network namespaces, device trees, and memory), but each distribution has its own independent PID namespace, user namespace, mount namespace, and init process. This design brings higher flexibility, performance, and isolation, reducing conflicts and improving stability. π οΈ
-
Comparison of WSL 1 and WSL 2: A brief comparison of the differences in performance, kernel usage, and file system handling between the two, with WSL 2 being the clear superior choice. β‘

-
WSL Architecture Diagram: Demonstrates how WSL 2 uses a lightweight VM to run Linux containers and explains how each component interacts, helping to understand the magic behind it. π§π»πΊοΈ

How to Install WSL π§π

Installing WSL is very simple. Just follow the steps below, and you will be set up in no time. π₯οΈβ¨
Prerequisites π
-
Windows 10 version 2004 or higher (Build 19041+) or Windows 11 πͺ
Installation Steps π οΈ
Open PowerShell or Command Prompt with administrator privileges:
-
Right-click the “Start” button and select “Windows PowerShell (Admin)” or “Command Prompt (Admin)”.
-
You must run as administrator to install WSL. πΌ
Install WSL:
-
In PowerShell / Command Prompt, enter the following command: wsl –install

-
By default, the Ubuntu distribution will be installed and set as WSL 2 (recommended). π
Custom Installation (Optional):
-
Want to use a different Linux distribution? You can use the following command: wsl –install -d <Distribution Name>
-
Replace < Distribution Name > with your preferred Linux distribution, such as Debian, Kali, or Fedora.
-
To see the list of available Linux distributions, enter:wsl –list –online or wsl -l -o π

Install from Microsoft Store (Optional):
-
You can also install Linux distributions directly from the Microsoft Store.
-
First, ensure that WSL is enabled in Windows Features settings:
1) Open the “Start” menu, search for “Windows Features”, and check “Windows Subsystem for Linux”.

2) Then, search for and install your preferred Linux distribution in the store. π¦

Restart your computer:
After installation is complete, restart your computer to apply the changes. π
Verify WSL Installation:
-
Open PowerShell or Command Prompt and enter:wsl -l -v to see the installed distributions and their versions. βοΈ

-
Set default version: wsl –set-default-version 2 You can switch to WSL 1, but WSL 2 is faster and more efficient. β‘
Upgrading from WSL 1 to WSL 2:
-
If you previously installed WSL 1, upgrading to WSL 2 is also simple. Run:
wsl –set-version <Distro Name> 2 Replace < Distro Name > with your Linux distribution name (e.g., Ubuntu). π§
Post-Installation Steps π

Launch the Linux Distribution:
-
Open the “Start” menu, search for the Linux distribution you just installed (like Ubuntu), and launch it. π

Set Username and Password:
-
On the first launch, you will be prompted to set a username and password for the WSL user. This will be your login credentials in the Linux environment. ποΈ

Start Exploring Your Linux Environment! π₯οΈπ

Once WSL is set up, you can directly enter the Linux command line, try using Linux commands, install packages, or run simple scripts, and enjoy the development experience! π


Connecting Spring Boot to Containerized Services in WSL π³
If you want to run a Spring Boot project on Windows while running MySQL, RabbitMQ, and Redis services in WSL through Docker, you can absolutely do it! No need for Docker Desktop, just WSL and Docker, running smoothly and stably. π
-
Step 1: Run Docker in WSL π₯οΈ
Before connecting anything, letβs make sure Docker is up and running in WSL.
1) Install Docker: Open the WSL terminal (like Ubuntu) and run the following command to install Docker:

2) Start Docker:

3) Verify if it started successfully

Now Docker has started successfully! π
-
Step 2: Set Up Services in Docker π
Use docker-compose to start MySQL, RabbitMQ, and Redis:
1) Create a docker-compose.yml file:
Example configuration:

2) Run the containers:

3) Verify


Connecting Spring Boot to Docker Services π
-
Configure in application.properties:

-
Start the Spring Boot project
In this example, I use JPA and Hibernate to automatically generate database tables based on the properties in the entity classes.JPA and Hibernate will automatically create the necessary tables in MySQL based on the entity classes in your Spring Boot project.

Access RabbitMQ Management Interface and Redis Insight π
Once your Spring Boot application is running and the related services are started in WSL , you can access the management interfaces of RabbitMQ and RedisInsight through a Windows browser.
RabbitMQ Management Interface:


Log in with the default username and password:
-
Username: guest
-
Password: guest
Redis Insight:
Similarly, access Redis Insight


Using IntelliJ IDEA with Projects in WSL π
For many developers, handling both backend and frontend technologies is the norm. In this example, you will use Java (Spring Boot) for the backend and React for the frontend.
With WSL (Windows Subsystem for Linux), you can easily set up both development environments without frequently switching operating systems.
Next, we will explore how to use IntelliJ IDEA (for Java development) and VS Code (for React/JS development) together with WSL to develop and collaborate on backend and frontend projects in a unified and consistent development environment.
Developing Java (Backend) in IntelliJ IDEA π₯οΈ
If your backend is developed based on Spring Boot (Java), then IntelliJ IDEA is likely your IDE of choice.
IntelliJ IDEA works seamlessly with WSL, allowing you to run backend Java applications directly in a Linux-based environment while working on your Windows machine.
How to Achieve This via WSL:
-
Install IntelliJ IDEA:
If you havenβt installed it yet, you can download and install IntelliJ IDEA from the JetBrains website.
-
Open the Project in IDEA:
Launch IDEA
In the Welcome Screen, click Open, then navigate to the Spring Boot project directory located in the WSL file system.

-
Configure Java SDK:
Ensure that IntelliJ IDEA is configured with the correct JDK in the WSL environment.
Do the following:
Β· Go to File > Project Structure.
Β· On the SDKs page, confirm that the Java SDK version matches that of WSL.

-
Run the Spring Boot Project

Running VS Code Projects in WSL π»

In this section, we will explore how to use VS Code in WSL to develop JavaScript and React projects while maintaining consistency and efficiency in the development environment.
Configuring VS Code for JavaScript (React) Projects in WSL π₯οΈ
If your frontend is built using React (JavaScript), VS Code is an excellent choice for developing and managing React applications. With WSL, you can create a smooth and efficient development experience in a Linux-based environment, even if you are using an IDE on Windows.
How to open and develop React projects in VS Code via WSL:
-
Install VS Code:
Download and install VS Code from the VS Code website.
-
Install the Remote – WSL Extension:
RunVS Code.
Open the Extensions Marketplace and search for “Remote – WSL“
Install the Remote – WSL extension. This plugin allowsVS Code to open files directly from the WSL environment.
-
Open Your React Project in VS Code via WSL:
Press Ctrl + Shift + P in VS Code to open the command palette.
Type and select Remote-WSL: Connect to WSL to open a new window directly in WSL.

-
Now, open the React project located in the WSL file system

-
Run npm install and npm run dev

-
Open the browser via the pop-up window or access it using the port, such as localhost:3000


END


Author: Fatih Khoiri
Reviewer: Shan Zhongdi
Editor: Zhu Sicong