I am trying to build packer and I am getting this error:
go install golang.org/x/tools/cmd/vet: open /usr/lib/go/pkg/tool/linux_amd64/vet: permission denied
Makefile:40: recipe for target 'test' failed
make: *** [test] Error 1
Is the installer trying to access my /usr folder? Should I run this under root? How can I fix this?
go vet is special, in that it's a tool that needs to go in GOROOT. In most installations GOROOT is also user writable, but if you installed via a package manager it won't be.
To work around this, you can do this as root to avoid changing any permissions in your GOPATH:
GOPATH=/tmp/tmpGOPATH go get golang.org/x/tools/cmd/vet
rm -rf /tmp/tmpGOPATH
Since vet is a tool provided by the official distribution, not having it installed may be considered a bug in gentoo's go package. The official go binary distribution included the following tools:
addr2line
api
asm
cgo
compile
cover
dist
doc
fix
link
nm
objdump
pack
pprof
tour
trace
vet
yacc
Related
I want to run a program on my Macbook.
First I run it with go run main.go. It is compiled successfully but indicates permission denied when running.
So I switch to sudo go run main.go. but it fails in the compiling stage, showing compile: version "go1.17.8" does not match go tool version "go1.18".
then after some tries, I find this file named ~/Library/Application\ Support/go/env which sets the configuration GOROOT=~/sdk/go1.17.8.
I cannot figure out what leads to these.
https://github.com/ChainSafe/ChainBridge
Why does this command not work?
make build
I cloned the repo locally, cd'd into the right folder; all I get back in the Git CLI is
> \033[32mBuilding binary...\033[0m
cd cmd/chainbridge && env GOARCH=amd64 go build -o ../../build/chainbridge -ldflags="-X main.Version=v.1.1.2-2-g6f55404"
env: ‘go’: No such file or directory
make: *** [Makefile:43: build] Error 127
I downloaded Go for Windows 10 64 bit, version 1.16.4
With Go, you don't really need to use Makefiles anymore. I think people just do it out of habit. I don't agree with the practice, as Go is a new language, and I don't like to see people misuse it by continuing to work with old crappy tools from the past. To that end, you can just download the code, then change location to:
cmd\chainbridge
Then run:
go build
I know this works, as I just did it with go version go1.16.3 windows/amd64. Also, you need to make sure go.exe is on your PATH. You probably need to add C:\go\bin or similar.
For example, when I run this
GOOS="windows" GOARCH="386" go install ./something
The executable would be created at
$GOROOT/bin/$GOOS_$GOARCH/something.exe
I want the executable to be created at
path/to/my/module/bin/$GOOS_$GOARCH/something.exe
EDIT
To clarify, I ask the question in the context of cross compiled builds inside a module.
I get the desired result using this command inside my module. I'd like to avoid specifying the path.
GOOS="windows" GOARCH="386" go build -o ./bin/$GOOS_$GOARCH/something.exe ./something
So, is it possible to get the same with go install?
Setting GOBIN results in an error
GOBIN=$(pwd)/bin GOOS="windows" GOARCH="386" go install ./something
# go install: cannot install cross-compiled binaries when GOBIN is set
Don't use go install for cross compiling. Use go build with -o flag.
Here is some history regarding GOBIN, robpike posted an issue stating "I have $GOBIN set but the go tool is ignoring it when installing..."
This article mentions
"When cross compiling, you should use go build, not go install. This is the one of the few cases where go build is preferable to go install...
The reason for this is go install always caches compiled packages, .a files, into the pkg/ directory that matches the root of the source code...
This logic also holds true for the standard library, which lives in /usr/local/go/src, so will be compiled to /usr/local/go/pkg/$GOOS_$GOARCH. This is a problem, because when cross compiling the go tool needs to rebuild the standard library for your target, but the binary distribution expects that /usr/local/go is not writeable.
Using go build rather that go install is the solution here, because go build builds, then throws away most of the result (rather than caching it for later), leaving you with the final binary in the current directory, which is most likely writeable by you"
go build is unable to find the 'appdynamics' package, even though the GOPATH is properly set. I downloaded the package, copied it onto the GOPATH: ~/go/src/appdynamics and ran go install appdynamics. I am using go v.1.10 on Ubuntu 18.4.
Visual Studio Code is able see the package and code completion works within the IDE. However, running go get -fix -v appdynamics produces the following error:
warning: no cgo types: exit status 1
warning: no cgo types: exit status 1
I have also tested this using the github.com/appdynamics namespace per the appdynamics go-sdk instructions. Also, I am aware of all the other go build 'cannot find package' questions on S.O.
Im new to go and I have been unable to find any thing online for my issue.
I have downloaded this code https://github.com/hashicorp/http-echo and I would like to set it up so I can run this command.
$ http-echo -listen=:8080 -text="hello world"
I have been getting quite a few different path issues.
Currently I have the code sitting in this directory.
/Users/jon/go/src/github.com/hashicorp
When I try and install it I get this error
$ go install http-echo
can't load package: /usr/local/go/src/http-echo/handlers.go:9:2: non-standard import "github.com/hashicorp/http-echo/version" in standard package "http-echo"
Where should I keep go projects on an OSX computer, and how do I get this to install or compile?
The code currently seems to be in /usr/local/go/src/http-echo. Packages should always reside in the directory $GOPATH/src/package-name, e.g.: $GOPATH/src/github.com/hashicorp/http-echo. (unless you're using go modules).
It should work if you move the source to the correct path (/Users/jon/go/src/github.com/hashicorp/http-echo). Then execute:
go install github.com/hashicorp/http-echo
Even easier would be to use go get to download the package in the first place. Simply run the following command from any directory:
go get github.com/hashicorp/http-echo
And http-echo is automagically installed.
If you still get an error after this, make sure $GOPATH/bin is in your $PATH.