Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clone on WSL gives "permission denied" error [WSL1]

I'm currently using WSL as my development environment for a work project. When running an npm install on a company project, I receive this error:

Command failed: /usr/bin/git clone -q <redacted url> /home/ambrose/.npm/_cacache/tmp/git-clone-393358b0
/home/ambrose/.npm/_cacache/tmp/git-clone-393358b0/.git: Permission denied

However, if I create the folder manually using mkdir, the install proceeds until it hits another folder that it cannot create.

The IntelliJ project is on my Windows hard drive (/mnt/d/...), if that makes any difference.

My question is: how can I avoid having to create every folder by hand during this npm install, and what seems to be the underlying problem?

like image 631
Numilani Avatar asked Jul 25 '18 15:07

Numilani


1 Answers

What I discovered is that WSL was incorrectly handling file locking and file access. My editor was accessing the directory at the same time as NPM, which was causing locking errors.

While I no longer use WSL on a daily basis for work, this issue seems to have been resolved with more recent updates to WSL. If the issue crops up again, the way I fixed the issue was:

  • close the file or folder in question within the editor and rerun the command.
  • If the issue persists, close the editor and rerun the command.

I hope this helps someone.

like image 192
Numilani Avatar answered Oct 06 '22 20:10

Numilani