golang mkdir /usr/local/go/pkg/mod permission denied
Asked Answered
S

4

13

OS: Windows 11 WSL2; IDE: Goland Latest

I am trying to open my IDE Goland, but I get this error when the IDE tries to index my project.

warning: GOPATH set to GOROOT (/usr/local/go) has no effect
go: mkdir /usr/local/go/pkg/mod: permission denied
go: github.com/MyCompany/[email protected]: mkdir /usr/local/go/pkg/mod: permission denied

though, I already set my go like this

 export GOROOT=/usr/local/go
 export GOPATH=$HOME/go
 export PATH=$PATH:/usr/local/go/bin

is that anything I miss for my WSL for Go Path?

Seventy answered 5/11, 2022 at 6:12 Comment(2)
Never set GOROOT. Make sure Your IDE knows about your GOPATH (or unset it).Sepulchre
What do you have in the IDE settings under Go | GOROOT and Go | GOPATH?Cromer
T
1

if you have this problem on linux
go inside your go installation directory
the default installation is /usr/local
and change the permissions sudo chmod -R 775 .

Tintometer answered 25/11, 2023 at 8:44 Comment(0)
R
0

Faced the similar issue of permission denied error while installing go analysis tools. The problem for me was while installing golang that means extracting the content of golang tar file i used sudo, something like below

sudo tar -C ./ -xzf go1.21.4.linux-amd64.tar.gz

this assigned the go binary dir to root user as owner and vs code is running from my own user which caused this error.

Re-installing go without sudo should fix the problem. Hope it helps 👍

Retiary answered 11/11, 2023 at 17:19 Comment(0)
F
0

I had a similar problem where when I tried to download new go packages, I saw a permission denied error (as shown below)

-> unzip /home/sandeepdev/go/pkg/mod/cache/download/github.com/aws/aws-sdk-go-v2/credentials/@v/v1.13.18.zip: mkdir /home/sandeepdev/go/pkg/mod/github.com/aws/aws-sdk-go-v2/[email protected]: permission denied

FYI, In my Ubuntu VM, my go path is /home/sandeepdev/go. So, I executed the below command:

sudo chown <user> -R  /home/sandeepdev/go

Where in my case, <user> = sandeepdev.

The above worked for me. Let me know if it's not :)

Fagin answered 30/5 at 15:13 Comment(0)
A
-3

Step 1: Open your terminal check GOPATH

mrone.inc

go env | grep GOPATH  

Step 2: Copy your GOPATH and them to ~/.zshrc

mrone.inc

mrone.inc

sudo gedit ~/.zshrc

Step 3: Save and reboot bash

mrone.inc

source ~/.zshrc

Alternative: Make the current user as a root

mrone.inc

mrone.inc

sudo chown <user> -R  /root/
Andalusia answered 29/7, 2023 at 7:51 Comment(1)
not the way to solve it.Matrices

© 2022 - 2024 — McMap. All rights reserved.