在Golang中安装外部软件包

I am trying to import a package in my golang code. But it is showing me this error:

cannot find package "github.com/mattbaird/jsonpatch" in any of: /opt/go/src/github.com/mattbaird/jsonpatch (from $GOROOT) /chaincode/input/src/github.com/mattbaird/jsonpatch (from $GOPATH) /opt/gopath/src/github.com/mattbaird/jsonpatch "

Can somebody help me fix this?

Thanks.

Recheck your environment variables($GOPATH, $GOROOT).

The problem you are facing is that, your code is searching for the package github.com/mattbaird/jsonpatch in /opt/go/src/github.com/, /chaincode/input/src/github.com/ and /opt/gopath/src/github.com/ directories. But you have installed the package in C:\Users\xyz\go\src\github.com directory.

Ensure your $GOPATH environment variable is set up correctly.

Then double check the packages are installed, if not you need to install the package which you can do with.

go get github.com/mattbaird/jsonpatch