---
title: "Discussion on \"npm not working in WSL2\" | Hashnode"
description: "Discussion on \"npm not working in WSL2\". When trying to run npm in WSL2 I got an error along these lines\n/mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter:\nAs the message indicates the problem is that WSL2 tries to run the Windows version of npm. You are supposed to be able to run..."
url: "https://hashnode.com/posts/npm-not-working-in-wsl2/5f55279bfb6cc91069300c64"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [npm not working in WSL2](https://dev.waltersson.com/npm-not-working-in-wsl2?utm_source=hashnode&utm_medium=feed)

When trying to run npm in WSL2 I got an error along these lines /mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: As the message indicates the problem is that WSL2 tries to run the Windows version of npm. You are supposed to be able to run...

Sep 6, 2020 · 1 min read · dev.waltersson.com  
Read the article

## Written by

[Joakim Waltersson](https://hashnode.com/@jwalter)

@jwalter

  
[View profile](https://hashnode.com/@jwalter)

Senior Architect at Cambio HealthCare Systems

## Responses 1

Markdown supported · ⌘↵ to post

[Amal Shaji](https://hashnode.com/@amal)

[Sep 7, 2020](https://hashnode.com/posts/npm-not-working-in-wsl2/5f55279bfb6cc91069300c64/comment/5f5626438bd8da1b2a5dc109)

wsl2 is trying to access node/npm installed on windows. This is because the windows environment variables are accessible through wsl2. You can turn this off by changing `appendWindowsPath=False in /etc/wsl.conf` .This disables all windows env variable access from wsl2. The downside is that you won't be able to use `explorer.exe`.

Another way is to use a node virtual environment like nodeenv and install everything inside the environment.

or you could remove the windows node/npm path from wsl2.

```
PATH=$(REMOVE_PART="/mnt/c/Program Files/nodejs" sh -c 'echo ":$PATH:" | sed "s@:$REMOVE_PART:@:@g;s@^:\(.*\):\$@\1@"')
```

My nodejs was installed in "/mnt/c/Program Files/nodejs". This will remove nodejs from the wsl path, it should work now. These are some other fixes.
