This is somewhat a follow-up to my last question: golang: installing packages in a local directory
I have GOPATH
set to $HOME/prog/go/gopath
and this path exists with three directories:
~/prog/go/gopath$ ls
bin pkg src
Now I try to install a module to access the redis database which asks me to run
go install
inside the source directory. But the command go install
gives me
~/prog/go/gopath/src/redis (go1)$ go install
go install flag: open /usr/local/go/pkg/darwin_amd64/flag.a: permission denied
~/prog/go/gopath/src/redis (go1)$ echo $GOPATH
<myhomedir>/prog/go/gopath
(where <myhomedir>
is a valid path)
Question 1: why does go install
not take $GOPATH
into account?
Question 2: how to convince go install
to use $GOPATH
?
GoSIG / go-sig According to the golang wiki: Go 1.17 (August 2021) will remove the GO111MODULE setting and GOPATH mode entirely, using module mode always.
You do not need to change this variable, unless you plan to use different Go versions. GOPATH is a variable that defines the root of your workspace. By default, the workspace directory is a directory that is named go within your user home directory (~/go for Linux and MacOS, %USERPROFILE%/go for Windows).
Open the MSI file you downloaded and follow the prompts to install Go. By default, the installer will install Go to Program Files or Program Files (x86) . You can change the location as needed.
Not sure how you setup go but it's possible that it needs to build packages from std library but can't due to permissions. You can try
cd /usr/local/go/src
sudo ./all.bash
This should build the std library and run tests to make sure everything is ok.
Make sure you have proper permissions to read and execute from $GOROOT as necessary. Personally I just download the archive from golang.org and keep it under ~/local/go and set GOROOT appropriately.
Similar problems here. When I check my $GOROOT, I find that all the libraries are already built there. But for some reasons, it tries to rebuild all the libraries. So I just do a little trick:
find /usr/lib/go/pkg/ -name "*.*" | sudo xargs touch
Then everything just work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With