Go Environment:
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/stack/mygo"
GORACE=""
GOROOT="/home/stack/go"
GOTOOLDIR="/home/stack/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
Go version:
$ go version
go version go1.6 linux/amd64
Error while running:
$ sudo -E go get -u golang.org/x/crypto/ssh
package golang.org/x/crypto/ssh
imports bufio: unrecognized import path "bufio"
package golang.org/x/crypto/ssh
imports bytes: unrecognized import path "bytes"
package golang.org/x/crypto/ssh
imports crypto: unrecognized import path "crypto"
package golang.org/x/crypto/ssh
sudo -E
changes you to root and preserves the environment variables. In this case, these are the env variables of the shell and not of go
.
You can read more about how sudo -E works here
Since your GOTOOLDIR="/home/stack/go/pkg/tool/linux_amd64"
shows that it is installed for the user stack
(probably) - you have to use go get
as user stack
Godep and vendor is worth looking into. Just like package managers like npm and pip, working with dependencies within the project directory prevent you from version clashes and avoid using $GOPATH
.
A simpler alternative is Glide. It greatly simplifies dependency management and works very similar to Godep
with glide.yaml
and glide.lock
files to control dependencies and their versions instead of Godep.json
.
If you've worked with npm
or cargo
, it's very similar:
# Create manifest
$ glide init
# Get packages
$ glide get path/to/package
# Update package
$ glide update
# Remove package
$ glide remove path/to/package
Packages are saved to vendor/
just like Godep does (in default Go 1.6 any way).