~/src/go-statsd-client> echo $GOPATH
/Users/me/gopath
~/src/go-statsd-client> echo $GOROOT
/usr/local/Cellar/go/1.1.1\\
~/src/go-statsd-client> go install
g
On OSX Mojave 10.14, go
is typically installed at /usr/local/go
.
Hence, setup these ENVs and you should be good to go.
export GOPATH=/usr/local/go && export GOBIN=/usr/local/go/bin
Also, add these to your bash_profile
or zsh_profile
if it works.
echo "export GOPATH=/usr/local/go && export GOBIN=/usr/local/go/bin" >> ~/.bash_profile && source ~/.bash_profile
I had this problem on Windows.
My problem was that my %GOPATH%
environment variable was set to
C:\Users\john\src\goworkspace
instead of
C:\Users\john\src\goworkspace\
Adding the missing trailing slash at the end fixed it for me.
Careful when running
export GOPATH=$HOME
Go assume that your code exists in specific places related to GOPATH
. So, instead, you can use docker to run any go command:
docker run -it -v $(pwd):/go/src/github.com/<organization name>/<repository name> golang
And now you can use any golang command, for example:
go test github.com/<organization name>/<repository name>
For any OS X users and future me, you also need to set GOBIN
to avoid this confusing message on install and go get
mkdir bin
export GOBIN=$GOPATH/bin
You need to setup both GOPATH
and GOBIN
. Make sure you have done the following (please replace ~/go
with your preferred GOPATH
and subsequently change GOBIN
). This is tested on Ubuntu 16.04 LTS
.
export GOPATH=~/go
mkdir ~/go/bin
export GOBIN=$GOPATH/bin
The selected answer did not solve the problem for me.
When you provide no arguments to go install
, it defaults to attempting to install the package in the current directory. The error message is telling you that it cannot do that, because the current directory isn't part of your $GOPATH
.
You can either:
$GOPATH
to your $HOME (export GOPATH=$HOME
).$GOPATH
(mv ~/src/go-statsd-client /User/me/gopath
).After either, going into the go-statsd-client
directory and typing go install
will work, and so will typing go install go-statsd-client
from anywhere in the filesystem. The built binaries will go into $GOPATH/bin
.
As an unrelated suggestion, you probably want to namespace your package with a domain name, to avoid name clashing (e.g. github.com/you/go-statsd-client
, if that's where you hold your source code).