Mirpur, Dhaka-1216
+8801684-618959

To install OpenCode in the Windows Subsystem for Linux (WSL), first, we need to install a Linux distribution such as Kali Linux or Ubuntu. But today we will work with Kali Linux. Things to remember: this setup lets you run Kali-Linux tools directly from Windows without installing any third-party virtual machine. Another thing to remember is the use of WSL 2 for better performance and full Linux kernel support.

System Requirements

To do this setup, the requirements are –

  • Windows 10 version 2004+ or Windows 11
  • Virtualization is enabled in the BIOS
  • Administrator access

Step-by-Step Guide to Install OpenCode in Windows Subsystem for Linux WSL

Step 1: Enable Windows Subsystem for Linux (WSL)

Before installing any Linux distribution on our pc, we need to enable the Windows Subsystem for Linux (WSL) feature in Windows. WSL, which means Windows Subsystem for Linux, allows you to run a Linux environment directly inside Windows without using a virtual machine. There are two common methods to enable Windows Subsystem for Linux (WSL)

Method 1: Enable WSL Manually from Windows Features

1. Click the Search box in Windows.

2. Type “Turn Windows features on or off” and open it.

turn-windows-features-on-or-off
Turn Windows features on or off

3. A Windows Features window will appear.

4. Scroll down and check the option Windows Subsystem for Linux.

Select Windows Subsystem for linux
Select Windows Subsystem for Linux

5. Click OK.

6. Restart your computer when prompted.

Method 2: Enable WSL Using PowerShell (Recommended)

My recommendation is to use Windows PowerShell, which is easier than the previous method. To do this –

1. Open PowerShell as Administrator.

  • Click on the Search Box in Windows
  • Type “PowerShell or Windows PowerShell” and open it.
Open Windows PowerShell
Open Windows PowerShell

2. Run the following command:

wsl --install

This command will automatically:

  • Enable Windows Subsystem for Linux
  • Enable Virtual Machine Platform
  • Download the latest WSL kernel
  • Install the default Linux distribution

3. Restart your computer after the installation finishes.

After the reboot, WSL will be fully activated.

Alternative Method โ€” Enable WSL Manually (Not Recommended)

If the automatic command does not work, discussed in method-2, then enable the features manually.

  1. Open PowerShell as Administrator
  2. Run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Then enable the Virtual Machine platform:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  1. Restart your computer.

Now, to confirm WSL is installed:

wsl --status

Step 2: Install Kali Linux Distribution Using PowerShell

Once we complete step 1, so WSL is enabled, we can install a Linux distribution. So, as I mentioned before, in this guide, we install Kali Linux. As we know, Kali Linux itself is widely used for penetration testing, cybersecurity research, and ethical hacking.

1. Check Available Linux Distributions

Open PowerShell and run:

wsl --list --online

This command will show all available Linux distributions that we can install. Look at the image below.

Example output:

2. Install Kali Linux

Now, run the following command:

wsl --install -d kali-linux

This will download Kali Linux andinstall it inside WSL. Also, configure the Linux environment.

The installation may take several minutes; it totally depends on your internet speed.

An alternative way to install Kali Linux via the Microsoft Store

This is an easy way, but keep in mind that if you want to install Kali Linux from the Microsoft Store, then you must follow the โ€œMethod 1: Enable Windows Subsystemโ€; otherwise, Kali Linux will not work. To do this –

  1. Open Microsoft Store
  2. Search for โ€œKali Linuxโ€
  3. Click Install

3. Launch Kali Linux

After completing the installation, open Kali Linux in PowerShell by running the following command:

wsl -d kali-linux

Or we can launch it from the Start Menu by searching for Kali Linux. And even if we type “Kali Linux” into the Windows Search box now, we will see it listed as an option to open.

4. Create Linux Username and Password

The first time you start Kali, it will ask you to create a Linux user account and to set a password.

Example:

This account will be used to access the Kali Linux environment.

5. Verify the Installation

Run the following command inside Kali Linux:

uname -a

If the installation is successful, it will show the Linux kernel running under WSL.

Step 3: Update Kali Linux packages

After the first login, we need to update. This is recommended:

sudo apt update && sudo apt upgrade -y

Step 4: Verify WSL Version

Now, to check detailed information about all installed Linux distributions in WSL, run the following command.

wsl --list --verbose

You should see: 

wsl--list-verbose
Command wsl–list-verbose result

 Version: 2. If not, convert it:

wsl --set-version kali-linux 2

In my PC, Kali Linux is now successfully running inside WSL 2.

Optional Step: Common Issues and Fixes

While installing or running Windows Subsystem for Linux (WSL), you may encounter some common problems. The following solutions can help resolve them. If you arenโ€™t facing any issues, then skip this part.

Issue 1: Virtualization Not Enabled

Problem

WSL installation fails or shows errors related to virtualization. Example messages may include:

  • โ€œVirtual Machine Platform is required.โ€
  • โ€œWSL 2 requires virtualization support.โ€
Cause

WSL 2 requires CPU virtualization technology to be enabled. This feature is called:

  • Intel VT-x (for Intel processors)
  • AMD-V (for AMD processors)

If your PCโ€™s virtualization is disabled in the BIOS or UEFI firmware, WSL will not work correctly.

Solution
  1. Restart your computer.
  2. Enter the BIOS/UEFI settings during boot (usually by pressing F2, F10, DEL, or ESC).
  3. Locate the Virtualization Technology option.
  4. Enable one of the following:
    • Intel VT-x
    • AMD-V
  5. Save the settings and restart the computer.

After enabling virtualization, try installing or running WSL again.

Issue 2: WSL Not Responding or Not Starting

Problem

Sometimes you may face a Linux distribution, such as Kali Linux or Ubuntu fails to start or freezes.

Cause

Sometimes the WSL service becomes stuck in memory, or a previous session remains active.

Solution

You can restart WSL using Windows PowerShell.

  1. Open PowerShell.
  2. Run the following command:
wsl --shutdown

This command completely stops all running WSL instances.

  1. Start your Linux distribution again.

Example:

wsl

or

wsl -d kali-linux

This command will restart the WSL environment and usually resolve the issue.

Issue 3: WSL Version Compatibility

Problem

Some tools may not function correctly if the Linux distribution is running on WSL 1 rather than WSL 2, because certain tools require the enhanced compatibility and features provided by the newer WSL version available in Windows Subsystem for Linux.

Solution

Before proceeding with any changes, verify the Linux distributions currently installed by running the following command.

wsl --list --verbose

If your distribution is using version 1, you must upgrade it:

wsl --set-version kali-linux 2

WSL 2 provides better compatibility and performance.

Issue 4: EACCES Permission Errors with npm

Problem

When attempting to install npm packages globally, you might encounter an error message similar to the following:

This usually occurs when running commands such as:

npm install -g package-name
Cause

This error typically occurs when npm lacks the necessary permissions to write files to the global Node.js installation directory.

This commonly happens when Node.js is installed using the system package manager inside Kali Linux.

Quick Troubleshooting Checklist

If Windows Subsystem for Linux is not functioning properly on your computer, first check the following points to identify the possible cause.

  • Virtualization is enabled in the BIOS
  • Windows is updated
  • WSL features are installed
  • The distribution is running on WSL 2
  • Restart WSL using wsl –shutdown

Optional: Install Kali Tools Meta Package

Full Kali tools:

sudo apt install -y kali-linux-large

Minimal tools:

sudo apt install -y kali-linux-default

Step 5: Install Node.js and NPM

After setting up Kali Linux in Windows Subsystem for Linux, our next step is to install the OpenCode CLI. But before starting installation, first restart the terminal. Simply close the PowerShell terminal or Kali-Linux CLI terminal where you are working and then open it again.

As we know, OpenCode is a Node.js based AI tool. So, we will use NVM, which is known as Node Version Manager, to avoid permission issues.

1: Install NVM (Node Version Manager)

To install NVM inside our Linux terminal, we need to run the following command in our terminal –

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
source ~/.bashrc

2: Install the latest LTS Version of Node.js

nvm install --lts
nvm use --lts
Verify installation:
node -v
npm -v

Step 6: Install OpenCode CLI Globally

Now, to install OpenCode, run the following command:

npm install -g opencode-ai

No sudo is required when using NVM. Just copy the exact command that is shown above and run it in your terminal. If the previous step was done correctly, OpenCode will install nicely.

Step 7: Verify OpenCode Installation & Run the OpenCode in WSL

To verify whether opencode is successfully installed or not in your WSL system, run the following command below:

opencode --version

When you run this command in your terminal, you will see the OpenCode Version if installed successfully. In my case, it is now successfully installed and is ready to use inside Kali Linux (WSL).

Also test OpenCode installation using this command –

opencode --help

This command also helps us to confirm that the installation is working perfectly.

How do we use the OpenCode Inside VSCode that is installed in Windows Subsystem?

After successfully installing OpenCode on WSL, we can use it inside the Visual Studio Code editor in two simple ways.

Method 1: Open the Project Folder from WSL

To do this –

1. First, we will open Kali Linux inside the PowerShell terminal, or directly open the Kali Linux installed software list.

2. Navigate to your project directory in the terminal by using the following command.

cd  /mnt/d/xampp/htdocs/test-project

Note: In this command, “/d/” means the D drive; if your project is in the C Drive, then replace the “d” with “c”.

cd directory
Change Directory

3. Run the following command:

code .
Code . Command
Command to Open VS Code

Running this command will launch Visual Studio Code and load the current folder as the active workspace.

To run OpenCode within Visual Studio Code, first open the editorโ€™s integrated terminal using one of the methods below.

Method 1 โ€” Keyboard Shortcut

Ctrl + `

Method 2 โ€” From the Menu

View โ†’ Terminal

At the bottom of the VS Code window, the terminal panel will appear, which will allow you to run commands directly inside your project environment. Look at the image below –

Open terminal
Open Terminal

If Kali Linux is not opening in the Visual Studio terminal, then switch it manually. To do this:

1. Click the dropdown arrow located on the right side of the terminal panel.

2. Select Kali Linux (WSL) from the list.

For better clarity, refer to the image below:

Select Kali-Linux WSL
Select Kali-Linux WSL

The terminal will relaunch using the Kali Linux environment, which will allow Visual Studio Code to connect to WSL and run OpenCode AI directly within the editor.

Now, run the command – 

opencode
run opencode
Run Opencode

When you run the command “opencode“, it will take a few seconds to run the Opencode AI inside your VS Code terminal. Look at the image below.

This image is about write your prompt of Windows SubSystem for Linux WSL.
OpenCode Interface

Now you can use OpenCode AI by writing your desired prompt or giving your instructions, and take advantage of it in your design or development project.

Method 2: Open the Project Directly from Visual Studio Code

  1. Open Visual Studio Code.
  2. Click File โ†’ Open Folder.
  3. Select your project folder.
  4. Open Terminal
  5. Click the dropdown arrow located on the right side of the terminal panel.
  6. Select Kali Linux (WSL) from the list.

Now, like before, the terminal will relaunch using the Kali Linux environment, which will allow Visual Studio Code to connect to WSL and run OpenCode AI directly within the editor.

Now, run the command –

opencode

As I mentioned earlier, when you run this command, it will take a few seconds for the Opencode AI to run in your terminal. See the image below.

This image is about write your prompt of Windows SubSystem for Linux WSL.
OpenCode Interface

Now you can use OpenCode AI by writing your desired prompt or giving your instructions, and take advantage of it in your design or development project.

Why Use Kali in WSL?

  • No need for VirtualBox or VMware
  • Lightweight setup
  • Fast startup
  • Direct integration with the Windows filesystem
  • Ideal for penetration testing labs

Why Use NVM Instead of sudo npm?

  • Prevents EACCES permission errors
  • Avoids system-level conflicts
  • Allows multiple Node versions
  • Safer development environment

Conclusion

One of the most effective ways to use OpenCode is by installing it inside Kali Linux on Windows Subsystem for Linux (WSL). This setup allows you to run OpenCode seamlessly within Visual Studio Code on Windows, while WSL 2 delivers near-native performance without the overhead of traditional virtualization. For best results:

  • Always use WSL 2
  • Keep Kali updated

Author: Jahid Shah

An Expert WordPress Developer and Security Specialist with over 5 years of experience in theme installation, customization, frontend design, Malware Remove and Bug Fixing. I...

View all posts by Author

Follow Author:

Leave a Reply