Reputation: 19
I run the following command to install swag and the error message is as follows. I hope it helps.
MacBook-Pro~: go get -u github.com/swaggo/swag/cmd/swag 1 ↵ 5434 14:55:27
go: found github.com/swaggo/swag/cmd/swag in github.com/swaggo/swag v1.6.7
go: golang.org/x/text upgrade => v0.3.2
go: github.com/go-openapi/spec upgrade => v0.19.8
go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0
go: github.com/go-openapi/swag upgrade => v0.19.9
go: golang.org/x/tools upgrade => v0.0.0-20200612022331-742c5eb664c2
go: gopkg.in/yaml.v2 upgrade => v2.3.0
go: github.com/urfave/cli/v2 upgrade => v2.2.0
go: golang.org/x/net upgrade => v0.0.0-20200602114024-627f9648deb9
go: github.com/go-openapi/jsonreference upgrade => v0.19.3
go: github.com/go-openapi/jsonpointer upgrade => v0.19.3
go: github.com/PuerkitoBio/purell upgrade => v1.1.1
go: github.com/mailru/easyjson upgrade => v0.7.1
go get github.com/swaggo/swag/cmd/swag: copying /var/folders/jm/s7qg764x5y93_2_x64qwlswm0000gn/T/go-build542960688/b001/exe/a.out: open /usr/local/go/bin/swag: permission denied
I installed go via the pkg package, and here are my environment variables.
MacBook-Pro ~/Documents/goProjects/bin go env ✔ 5439 15:40:42
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/Users/zhangyu/Library/Caches/go-build"
GOENV="/Users/zhangyu/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/aaron/Documents/goProjects"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jm/s7qg764x5y93_2_x64qwlswm0000gn/T/go-build760572234=/tmp/go-build -gno-record-gcc-switches -fno-common"
How do I change the permissions, am I installing it incorrectly, or do I need to change the environment variables?
Upvotes: 0
Views: 7530
Reputation: 3241
It appears your $GOPATH
is set to /usr/local/go/
. Verify by running echo $GOPATH
in the terminal.
/usr/local/go
is usually owned by user root
. You personal user is not allowed to write stuff there, hence the error.
You have a couple of options:
$GOPATH
explicitly to a location you can read/write to. That should be something like [this] (https://gist.github.com/molivier/271bba5d67de1583a8e3). Note that I am not a Mac user and could not verify that this gist works.$GOPATH
to use the default: https://rakyll.org/default-gopath//usr/local/go/
. I am not gonna discribe how to achieve this because you should not do this anyway.If you have been working with go
before make sure you copy the directories /usr/local/go/bin
, /usr/local/go/pkg
and /usr/local/go/src
to your new $GOPATH
.
Upvotes: 1