dongtangyi8962 2016-09-23 14:49
浏览 66

如何在Ubuntu 16.04 LTS中的golang中正确使用多个工作区?

I had installed go-1.6 in Ubuntu 16.04 LTS. I also had set up two different workspaces and the $GOPATH by specifying the location of both the workspaces in it.

But one of the workspaces(primary or main workspace) is working correctly while the other one(secondary workspace) is not working. I wish to use the secondary workspace for practising web app development in golang and the primary one for my projects. Both these workspaces have different packages in them as I am using them for different purposes. While working with the secondary workspace, I am getting errors like 'package not found' when I import packages in my programs . The 'go build' tool is looking for those packages in the primary workspace but they are present in secondary workspace. I am using Atom editor by GitHub.

Even when I install packages using 'go get', the packages are installed in the primary workspace.

The 'go environment variables' are as follows :-

gkv@GKVInnovations:~$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/gkv/Desktop/goWorkspace:/home/gkv/Desktop/Business/Backend"
GORACE=""
GOROOT="/usr/lib/go-1.6"
GOTOOLDIR="/usr/lib/go-1.6/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

Location of the primary workspace :- /home/gkv/Desktop/goWorkspace

Location of the secondary workspace :- /home/gkv/Desktop/Business/Backend

Please help me to resolve this issue and improve my workflow!

  • 写回答

2条回答 默认 最新

  • dpzr52746 2016-09-23 14:56
    关注

    You are using Atom, which makes it harder to change GOPATH.

    Go searches each directory listed in GOPATH to find source code, but new packages are always downloaded into the first directory in the list.

    From https://golang.org/cmd/go/#hdr-GOPATH_environment_variable

    Even though the GOPATH may be a list of directories, it is generally correct and sufficient to use a single GOPATH for all Go code on your machine. Since all packages retrieved with "go get" have a unique URL (and thus a unique path on disk), having more than one GOPATH is almost never necessary when building with the Go tool.

    From https://github.com/golang/go/wiki/GOPATH#use-a-single-gopath

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料