root@ubuntu:~/kata# go get -d -u github.com/kata-containers/runtime Command 'go' not found, but can be installed with: snap install go # version 1.15.2, or apt install golang-go apt install gccgo-go See 'snap info go' for additional versions. root@ubuntu:~/kata# apt install golang-go Reading package lists... Done Building dependency tree Reading state information... Done
root@ubuntu:~/kata# go version go version go1.10.4 linux/arm64 root@ubuntu:~/kata#
root@ubuntu:~/kata# ls /usr/bin/go -al lrwxrwxrwx 1 root root 21 Feb 28 2018 /usr/bin/go -> ../lib/go-1.10/bin/go root@ubuntu:~/kata# whereis go go: /usr/bin/go /usr/lib/go /usr/share/go /usr/share/man/man1/go.1.gz root@ubuntu:~/kata#
apt-get install golang-go
这样安装版本可能过低。
go version
查看版本为 1.6.2。
apt-get 卸载此版本重新安装
重新安装
- 下载
wget https://studygolang.com/dl/golang/go1.11.linux-amd64.tar.gz
- 下载
- 解压缩
tar -zxvf go1.11.linux-amd64.tar.gz -C /usr/lib
- 解压缩
- 设置添加环境变量
vi /etc/profile
在最后面添加如下配置
- 设置添加环境变量
export GOPATH=/opt/gopath
export GOROOT=/usr/lib/go
export GOARCH=386
export GOOS=linux
export GOTOOLS=$GOROOT/pkg/tool
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
- 执行
source /etc/profile
- 执行
- 查看版本
go version
结果go version go1.11 linux/amd64
- 查看版本
用git clone 代替go get
root@ubuntu:~/kata# go get -d -u github.com/kata-containers/runtime package github.com/kata-containers/runtime: no Go files in /root/go/src/github.com/kata-containers/runtime root@ubuntu:~/kata#
root@ubuntu:~/kata# git clone https://github.com/kata-containers/runtime.git
consider the following goreleaser.yml # goreleaser.yml # Build customization build: goos: - windows - darwin - linux goarch: - amd64 - arm - arm64 - 386
root@ubuntu:~/kata/runtime# go env
cmd/go: unsupported GOOS/GOARCH pair linux/arch64
arch64 改成arm64
export GOPATH=/opt/gopath export GOROOT=/usr/lib/go export GOARCH=arm64 export GOOS=linux export GOTOOLS=$GOROOT/pkg/tool export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
root@ubuntu:~/kata/runtime# source ../go_source root@ubuntu:~/kata/runtime# go env GOARCH="arm64" GOBIN="" GOCACHE="/root/.cache/go-build" GOEXE="" GOHOSTARCH="arm64" GOHOSTOS="linux" GOOS="linux" GOPATH="/opt/gopath" GORACE="" GOROOT="/usr/lib/go" GOTMPDIR="" GOTOOLDIR="/usr/lib/go/pkg/tool/linux_arm64" GCCGO="gccgo" CC="aarch64-linux-gnu-gcc" CXX="g++" CGO_ENABLED="1" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build751817124=/tmp/go-build -gno-record-gcc-switches" root@ubuntu:~/kata/runtime#
root@ubuntu:~/kata/runtime# make && sudo -E PATH=$PATH make install INFO: yq was not found, installing it golang.mk:60: *** "ERROR: golang minor version too old: got 1.10.4, need atleast 1.11". Stop. root@ubuntu:~/kata/runtime#
root@ubuntu:~/kata# apt-get purge golang-go
tar -zxvf go1.15.2.linux-arm64.tar.gz -C /usr/lib
root@ubuntu:~/kata# cat go_source export GOPATH=/opt/gopath export GOROOT=/usr/lib/go export GOARCH=arm64 export GOOS=linux export GOTOOLS=$GOROOT/pkg/tool export PATH=$PATH:$GOROOT/bin:$GOPATH/bin root@ubuntu:~/kata# source go_source root@ubuntu:~/kata# go -v flag provided but not defined: -v Go is a tool for managing Go source code.
BUILD /root/kata/runtime/kata-runtime kata-env.go:14:2: cannot find package "github.com/BurntSushi/toml" in any of: /usr/lib/go/src/github.com/BurntSushi/toml (from $GOROOT) /opt/gopath/src/github.com/BurntSushi/toml (from $GOPATH) utils.go:15:2: cannot find package "github.com/blang/semver" in any of: /usr/lib/go/src/github.com/blang/semver (from $GOROOT) /opt/gopath/src/github.com/blang/semver (from $GOPATH) update.go:15:2: cannot find package "github.com/docker/go-units" in any of: /usr/lib/go/src/github.com/docker/go-units (from $GOROOT) /opt/gopath/src/github.com/docker/go-units (from $GOPATH) factory.go:18:2: cannot find package "github.com/gogo/protobuf/types" in any of: /usr/lib/go/src/github.com/gogo/protobuf/types (from $GOROOT) /opt/gopath/src/github.com/gogo/protobuf/types (from $GOPATH) create.go:15:2: cannot find package "github.com/kata-containers/runtime/pkg/katautils" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/pkg/katautils (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/pkg/katautils (from $GOPATH) main.go:21:2: cannot find package "github.com/kata-containers/runtime/pkg/signals" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/pkg/signals (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/pkg/signals (from $GOPATH) factory.go:19:2: cannot find package "github.com/kata-containers/runtime/protocols/cache" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/protocols/cache (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/protocols/cache (from $GOPATH) create.go:16:2: cannot find package "github.com/kata-containers/runtime/virtcontainers" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/virtcontainers (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/virtcontainers (from $GOPATH) kata-env.go:17:2: cannot find package "github.com/kata-containers/runtime/virtcontainers/experimental" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/virtcontainers/experimental (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/virtcontainers/experimental (from $GOPATH) factory.go:21:2: cannot find package "github.com/kata-containers/runtime/virtcontainers/factory" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/virtcontainers/factory (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/virtcontainers/factory (from $GOPATH) delete.go:16:2: cannot find package "github.com/kata-containers/runtime/virtcontainers/pkg/annotations" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/virtcontainers/pkg/annotations (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/virtcontainers/pkg/annotations (from $GOPATH) create.go:17:2: cannot find package "github.com/kata-containers/runtime/virtcontainers/pkg/compatoci" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/virtcontainers/pkg/compatoci (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/virtcontainers/pkg/compatoci (from $GOPATH) create.go:18:2: cannot find package "github.com/kata-containers/runtime/virtcontainers/pkg/oci" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/virtcontainers/pkg/oci (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/virtcontainers/pkg/oci (from $GOPATH) main.go:26:2: cannot find package "github.com/kata-containers/runtime/virtcontainers/pkg/rootless" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/virtcontainers/pkg/rootless (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/virtcontainers/pkg/rootless (from $GOPATH) network.go:14:2: cannot find package "github.com/kata-containers/runtime/virtcontainers/pkg/types" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/virtcontainers/pkg/types (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/virtcontainers/pkg/types (from $GOPATH) events.go:17:2: cannot find package "github.com/kata-containers/runtime/virtcontainers/types" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/virtcontainers/types (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/virtcontainers/types (from $GOPATH) kata-env.go:19:2: cannot find package "github.com/kata-containers/runtime/virtcontainers/utils" in any of: /usr/lib/go/src/github.com/kata-containers/runtime/virtcontainers/utils (from $GOROOT) /opt/gopath/src/github.com/kata-containers/runtime/virtcontainers/utils (from $GOPATH) spec.go:16:2: cannot find package "github.com/opencontainers/runc/libcontainer/specconv" in any of: /usr/lib/go/src/github.com/opencontainers/runc/libcontainer/specconv (from $GOROOT) /opt/gopath/src/github.com/opencontainers/runc/libcontainer/specconv (from $GOPATH) oci.go:20:2: cannot find package "github.com/opencontainers/runc/libcontainer/utils" in any of: /usr/lib/go/src/github.com/opencontainers/runc/libcontainer/utils (from $GOROOT) /opt/gopath/src/github.com/opencontainers/runc/libcontainer/utils (from $GOPATH) exec.go:21:2: cannot find package "github.com/opencontainers/runtime-spec/specs-go" in any of: /usr/lib/go/src/github.com/opencontainers/runtime-spec/specs-go (from $GOROOT) /opt/gopath/src/github.com/opencontainers/runtime-spec/specs-go (from $GOPATH) main.go:28:2: cannot find package "github.com/opentracing/opentracing-go" in any of: /usr/lib/go/src/github.com/opentracing/opentracing-go (from $GOROOT) /opt/gopath/src/github.com/opentracing/opentracing-go (from $GOPATH) factory.go:23:2: cannot find package "github.com/pkg/errors" in any of: /usr/lib/go/src/github.com/pkg/errors (from $GOROOT) /opt/gopath/src/github.com/pkg/errors (from $GOPATH) delete.go:18:2: cannot find package "github.com/sirupsen/logrus" in any of: /usr/lib/go/src/github.com/sirupsen/logrus (from $GOROOT) /opt/gopath/src/github.com/sirupsen/logrus (from $GOPATH) create.go:19:2: cannot find package "github.com/urfave/cli" in any of: /usr/lib/go/src/github.com/urfave/cli (from $GOROOT) /opt/gopath/src/github.com/urfave/cli (from $GOPATH) console.go:16:2: cannot find package "golang.org/x/sys/unix" in any of: /usr/lib/go/src/golang.org/x/sys/unix (from $GOROOT) /opt/gopath/src/golang.org/x/sys/unix (from $GOPATH) factory.go:26:2: cannot find package "google.golang.org/grpc" in any of: /usr/lib/go/src/google.golang.org/grpc (from $GOROOT) /opt/gopath/src/google.golang.org/grpc (from $GOPATH) Makefile:568: recipe for target '/root/kata/runtime/kata-runtime' failed make: *** [/root/kata/runtime/kata-runtime] Error 1
安装grpc
factory.go:26:2: cannot find package "google.golang.org/grpc" in any of: /usr/lib/go/src/google.golang.org/grpc (from $GOROOT) /opt/gopath/src/google.golang.org/grpc (from $GOPATH)
root@ubuntu:~/kata# mkdir go_package root@ubuntu:~/kata# cd go_package/ root@ubuntu:~/kata/go_package# ls root@ubuntu:~/kata/go_package# git clone https://github.com/grpc/grpc-go ./google.golang.org/grpc Cloning into './google.golang.org/grpc'... remote: Enumerating objects: 18, done. remote: Counting objects: 100% (18/18), done. remote: Compressing objects: 100% (17/17), done. remote: Total 22065 (delta 1), reused 6 (delta 0), pack-reused 22047 Receiving objects: 100% (22065/22065), 11.72 MiB | 1.34 MiB/s, done. Resolving deltas: 100% (13601/13601), done. root@ubuntu:~/kata/go_package#
root@ubuntu:~/kata/go_package# ls google.golang.org root@ubuntu:~/kata/go_package# go install google.golang.org/grpc cannot find package "google.golang.org/grpc" in any of: /usr/lib/go/src/google.golang.org/grpc (from $GOROOT) /opt/gopath/src/google.golang.org/grpc (from $GOPATH)
root@ubuntu:~/kata/go_package# ls google.golang.org root@ubuntu:~/kata/go_package# ls google.golang.org/ grpc root@ubuntu:~/kata/go_package# ls google.golang.org root@ubuntu:~/kata/go_package# ls /opt/gopath/src/ ls: cannot access '/opt/gopath/src/': No such file or directory root@ubuntu:~/kata/go_package# mkdir -p /opt/gopath/src/ root@ubuntu:~/kata/go_package# ls google.golang.org root@ubuntu:~/kata/go_package# cp google.golang.org /opt/gopath/src/ -r root@ubuntu:~/kata/go_package#
root@ubuntu:~/kata/go_package# cp google.golang.org /opt/gopath/src/ -r root@ubuntu:~/kata/go_package# go install /opt/gopath/src/google.golang.org/grpc /opt/gopath/src/google.golang.org/grpc/credentials/credentials.go:31:2: cannot find package "github.com/golang/protobuf/proto" in any of: /usr/lib/go/src/github.com/golang/protobuf/proto (from $GOROOT) /opt/gopath/src/github.com/golang/protobuf/proto (from $GOPATH) /opt/gopath/src/google.golang.org/grpc/internal/binarylog/method_logger.go:28:2: cannot find package "github.com/golang/protobuf/ptypes" in any of: /usr/lib/go/src/github.com/golang/protobuf/ptypes (from $GOROOT) /opt/gopath/src/github.com/golang/protobuf/ptypes (from $GOPATH) /opt/gopath/src/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go:9:2: cannot find package "github.com/golang/protobuf/ptypes/duration" in any of: /usr/lib/go/src/github.com/golang/protobuf/ptypes/duration (from $GOROOT) /opt/gopath/src/github.com/golang/protobuf/ptypes/duration (from $GOPATH) /opt/gopath/src/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go:10:2: cannot find package "github.com/golang/protobuf/ptypes/timestamp" in any of: /usr/lib/go/src/github.com/golang/protobuf/ptypes/timestamp (from $GOROOT) /opt/gopath/src/github.com/golang/protobuf/ptypes/timestamp (from $GOPATH) /opt/gopath/src/google.golang.org/grpc/internal/transport/controlbuf.go:28:2: cannot find package "golang.org/x/net/http2" in any of: /usr/lib/go/src/golang.org/x/net/http2 (from $GOROOT) /opt/gopath/src/golang.org/x/net/http2 (from $GOPATH) /opt/gopath/src/google.golang.org/grpc/internal/transport/controlbuf.go:29:2: cannot find package "golang.org/x/net/http2/hpack" in any of: /usr/lib/go/src/golang.org/x/net/http2/hpack (from $GOROOT) /opt/gopath/src/golang.org/x/net/http2/hpack (from $GOPATH) /opt/gopath/src/google.golang.org/grpc/server.go:36:2: cannot find package "golang.org/x/net/trace" in any of: /usr/lib/go/src/golang.org/x/net/trace (from $GOROOT) /opt/gopath/src/golang.org/x/net/trace (from $GOPATH) /opt/gopath/src/google.golang.org/grpc/internal/channelz/types_linux.go:26:2: cannot find package "golang.org/x/sys/unix" in any of: /usr/lib/go/src/golang.org/x/sys/unix (from $GOROOT) /opt/gopath/src/golang.org/x/sys/unix (from $GOPATH) /opt/gopath/src/google.golang.org/grpc/status/status.go:34:2: cannot find package "google.golang.org/genproto/googleapis/rpc/status" in any of: /usr/lib/go/src/google.golang.org/genproto/googleapis/rpc/status (from $GOROOT) /opt/gopath/src/google.golang.org/genproto/googleapis/rpc/status (from $GOPATH) root@ubuntu:~/kata/go_package#
git clone https://github.com/golang/net.git /opt/gopath/src/google.golang.org/x/net git clone https://github.com/golang/text.git /opt/gopath/src/google.golang.org/x/text git clone https://github.com/google/go-genproto.git /opt/gopath/src/google.golang.org/genproto
下载依赖
如何自动下载所有依赖包? 大部分情况下大家下载 Go 项目都是使用go get命令,它除了会下载指定的项目代码,还会去下载这个项目所依赖的所有项目。 但是有的时候我们的项目由于各种原因并不是通过go get下载的,是通过git clone下载的,这样代码下下来就没有依赖包了,没办法编译通过的。这样的话怎么办呢? go get -d -v ./... -d标志只下载代码包,不执行安装命令; -v打印详细日志和调试日志。这里加上这个标志会把每个下载的包都打印出来; ./...这个表示路径,代表当前目录下所有的文件。
root@ubuntu:~/kata/runtime# ls arch CODEOWNERS data Gopkg.toml Makefile protocols VERSION cli containerd-shim-v2 golang.mk hack netmon README.md versions.yaml CODE_OF_CONDUCT.md CONTRIBUTING.md Gopkg.lock LICENSE pkg vendor virtcontainers root@ubuntu:~/kata/runtime# go get -d -v ./... github.com/BurntSushi/toml (download) github.com/blang/semver (download) github.com/docker/go-units (download) github.com/gogo/protobuf (download)
root@ubuntu:~/kata/runtime# go get -d -v ./... github.com/BurntSushi/toml (download) github.com/blang/semver (download) github.com/docker/go-units (download) github.com/gogo/protobuf (download) github.com/kata-containers/runtime (download) github.com/opencontainers/runc (download) github.com/opencontainers/runtime-spec (download) github.com/opentracing/opentracing-go (download)
gopath目录