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.

3. A Windows Features window will appear.
4. Scroll down and check the option 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.

2. Run the following command:
wsl --installThis 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.
- Open PowerShell as Administrator
- Run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestartThen enable the Virtual Machine platform:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart- Restart your computer.
Now, to confirm WSL is installed:
wsl --statusStep 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 --onlineThis command will show all available Linux distributions that we can install. Look at the image below.
Example output:
NAME FRIENDLY NAME
Ubuntu Ubuntu
Debian Debian GNU/Linux
kali-linux Kali Linux Rolling
openSUSE openSUSE Leap2. Install Kali Linux
Now, run the following command:
wsl --install -d kali-linuxThis 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 –
- Open Microsoft Store
- Search for โKali Linuxโ
- Click Install
3. Launch Kali Linux
After completing the installation, open Kali Linux in PowerShell by running the following command:
wsl -d kali-linuxOr 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:
Enter new UNIX username: jahid
New password:
Retype new password:This account will be used to access the Kali Linux environment.
5. Verify the Installation
Run the following command inside Kali Linux:
uname -aIf 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 -yStep 4: Verify WSL Version
Now, to check detailed information about all installed Linux distributions in WSL, run the following command.
wsl --list --verboseYou should see:
NAME STATE VERSION
* kali-linux Running 2
Ubuntu Stopped 2
Version: 2. If not, convert it:
wsl --set-version kali-linux 2In 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
- Restart your computer.
- Enter the BIOS/UEFI settings during boot (usually by pressing F2, F10, DEL, or ESC).
- Locate the Virtualization Technology option.
- Enable one of the following:
- Intel VT-x
- AMD-V
- Intel VT-x
- 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.
- Open PowerShell.
- Run the following command:
wsl --shutdownThis command completely stops all running WSL instances.
- Start your Linux distribution again.
Example:
wslor
wsl -d kali-linuxThis 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 --verboseIf your distribution is using version 1, you must upgrade it:
wsl --set-version kali-linux 2WSL 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:
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! Error: EACCES: permission deniedThis usually occurs when running commands such as:
npm install -g package-nameCause
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-largeMinimal tools:
sudo apt install -y kali-linux-defaultStep 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 | bashsource ~/.bashrc2: Install the latest LTS Version of Node.js
nvm install --ltsnvm use --ltsVerify installation:
node -v
npm -vStep 6: Install OpenCode CLI Globally
Now, to install OpenCode, run the following command:
npm install -g opencode-aiNo 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 --versionWhen 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 --helpThis 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-projectNote: In this command, “/d/” means the D drive; if your project is in the C Drive, then replace the “d” with “c”.

3. Run the following command:
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 –

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:

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
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.

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
- Open Visual Studio Code.
- Click File โ Open Folder.
- Select your project folder.
- Open Terminal
- Click the dropdown arrow located on the right side of the terminal panel.
- 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 –
opencodeAs 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.

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






