0

At first, I tried to fix my problem of npm instruction

so I added

[interop] 
appendWindowsPath = false

to /etc/wsl.conf

It works, but another problem happen.

When I type code .

Command 'code' not found, did you mean:
  command 'node' from deb nodejs (12.22.9~dfsg-1ubuntu3)
  command 'cdde' from deb cdde (0.3.1-1build1)
  command 'ode' from deb plotutils (2.6-11)
  command 'tcode' from deb emboss (6.6.0+dfsg-11ubuntu1)
  command 'cde' from deb cde (0.1+git9-g551e54d-1.2)
Try: sudo apt install <deb name>

The above Error message appear.

I tried the following instruction

export PATH=$PATH:"/mnt/c/Users/%USERNAME%/AppData/Local/Programs/Microsoft VS Code/bin" 

It also works properly.

Whenever I restarted WSL, npm instruction still worked well, but code instruction lost its function again.

What should I do to fix the problem?

Thanks in advance!

AL-CEL
  • 21
  • 3

1 Answers1

0

My main suggestion would be to not use appendWindowsPath = false to fix your NPM problem. That's like using a sledgehammer as a flyswatter. As I said in this answer:

Please do not follow the recommendations (like this answer) to completely remove all Windows paths from WSL, as that will severely limit your ability to run Windows applications in WSL (one of its great features).

You'll also lose access to the ability to run PowerShell scripts and commands in WSL easily. You won't have direct access to wsl.exe itself from inside WSL (which comes in handy).

You can type the full paths to these commands, of course, but most instructions and other answers you find here are going to assume that you've left the Windows path intact.

Instead, figure out where npm is installed in your WSL distribution and then determine why it is further toward the end of the PATH than your Windows directories. Windows paths are added at the end of the Linux PATH for a reason. If something in your startup files is adding to the path, it should put it at the beginning, so it has precedence. E.g.:

export PATH="newdir:$PATH"

Note that I'm not saying that you should change your export statement above since, as mentioned, that Windows path would normally come at the end anyway. It's really not going to matter unless you put another code executable somewhere else in your path.

Whenever I restarted WSL, npm instruction still worked well, but code instruction lost its function again.

If you do want the "quick and dirty" (not recommended) solution, then you can simply add that export command that "makes it work" to your ~/.bashrc. That file is processed each time the Bash shell starts interactively.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70