WSL Permission Issues (chown /usr/local not done by installation)

Hey everyone,
I’m experiencing permission issues with linuxbrew on WSL where some brews are requiring me to use sudo.

I read through the faqs that describes why sudo is bad and why brew prefers to install to usr/local here: https://docs.brew.sh/FAQ

I followed the main installation instructions here and replaced bash_profile and /bin/bash with my zshrc since I prefer to use zsh. I even ran the install again while using the bash_profile and /bin/bash as mentioned in the docs.

My /usr/local looks like this:
rwxr-xr-x 1 root root 512 B Tue May 21 10:39:15 2019  ./
rwxr-xr-x 1 root root 512 B Tue May 21 10:39:15 2019  …/
rwxr-xr-x 1 root root 512 B Tue May 21 10:39:15 2019  bin/
rwxr-xr-x 1 root root 512 B Tue May 21 10:39:15 2019  etc/
rwxr-xr-x 1 root root 512 B Tue May 21 10:39:15 2019  games/
rwxr-xr-x 1 root root 512 B Tue May 21 10:39:15 2019  include/
rwxr-xr-x 1 root root 512 B Tue May 21 10:39:28 2019  lib/
rwxrwxrwx 1 root root 9 B Tue May 21 10:39:15 2019  man ⇒ share/man
rwxr-xr-x 1 root root 512 B Tue May 21 10:39:15 2019  sbin/
rwxr-xr-x 1 root root 512 B Sat Mar 7 15:49:34 2020  share/
rwxr-xr-x 1 root root 512 B Tue May 21 10:39:15 2019  src/

My PATH: Windows Terminal

/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/{usernamePlaceholder}/.npm-packages/bin:/home/linuxbrew/.linuxbre
w/bin:/home/linuxbrew/.linuxbrew/sbin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/usr/local/sbin:/us
r/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Wind
ows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files
(x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/Microsoft VS Code/bin:/mnt/
c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Users/{usernamePlaceholder}/scoop/shims:/mnt/c/Users/{usernamePlaceholder}/AppData/Local/Mi
crosoft/WindowsApps:/mnt/c/Program Files/Oracle/VirtualBox

I saw the following comment on Github that the homebrew installer should chown /usr/local for you: https://github.com/tj/n/issues/416#issuecomment-285112101

I installed “n”, a node version manager, and I received the following:
n lts
installing : node-v12.16.1
mkdir : /usr/local/n/versions/node/12.16.1
mkdir: cannot create directory ‘/usr/local/n’: Permission denied
Error: sudo required (or change ownership, or define N_PREFIX)

This is on a fresh reinstall of Windows 10 1904.

Should I simply chown the /usr/local directory and this will resolve it?

If so are there any other permissions that homebrew sets that I should set myself?

Or should I reinstall homebrew?

the /usr/local path is only applicable when talking about macOS. The install location on linux/WSL is /home/linuxbrew/.linuxbrew

1 Like

Oh okay thanks this makes a lot of sense.

I was also able to figure out the issue. This particular brew sets where it installs node versions to usr/local using the env variable N_PREFIX.

There’s an alternative installation method that doesn’t use homebrew called n-install.

I think one can simply set the variable to be home/username/n but I opted for using n-install instead.

Hi,

Just a quick question so I’m understanding properly.

Is it safe to create a directory in the root of /home/linuxbrew/.linuxbrew or is best practice to put it in a location like ./bin? Or I should avoid interfering with this directory altogether.

In general you should let the Homebrew directory be managed by Homebrew.