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

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line