dswu26846 2015-10-03 21:25
浏览 19
已采纳

去安装不起作用

I am using go version go1.5.1 linux/amd64 on debian 8.2 3.16.0-4-amd64. I installed golang using https://golang.org/doc/install.

This is what i put in my ~/.profile file

export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:/home/shivams/go/bin

Running go env on my machine is giving this output

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/shivams/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

Directory structure inside /home/shivams/go is {pkg,src,bin}. Inside src directory it is like test/hello.go.

If i am in src dir and run go run test/hello.go it is running perfectly. Also if i run go build test/hello.go it will create one executable hello file in same directory.

But if i try to run go install test/hello.go then i get this error go install: no install location for .go files listed on command line (GOBIN not set). If i set GOBIN explicitly then i am not able to see this error.

From what i read my understanding is that if GOPATH is set there is no need to set GOBIN variable.

Am i missing anything here? This is the first time i am trying go and not able to get this working.

  • 写回答

2条回答 默认 最新

  • doomm4711 2015-10-04 11:25
    关注

    As @JimB states, install is a command designed for packages. Just to give you a clear example, here is what I get when I run the go env command.

    GOARCH="amd64"
    GOBIN="/Users/quazinafiulislam/Code/go/ogolang/bin"
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOOS="darwin"
    GOPATH="/Users/quazinafiulislam/Code/go/ogolang"
    GORACE=""
    GOROOT="/usr/local/Cellar/go/1.5.1/libexec"
    GOTOOLDIR="/usr/local/Cellar/go/1.5.1/libexec/pkg/tool/darwin_amd64"
    GO15VENDOREXPERIMENT=""
    CC="clang"
    GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
    CXX="clang++"
    CGO_ENABLED="1"
    

    You will see that the GOPATH is set to my project root, ~/Code/go/ogolang. Now, lets see whats inside my project root.

    .
    ├── bin
    ├── pkg
    │   └── darwin_amd64
    └── src
        ├── bitbucket.org
        ├── github.com
        ├── golang.org
        ├── words
        └── wordtest
    

    As you can see I have a couple of packages. One of them is wordtest. I can use a go install on the words or wordtest packages. So, lets run go install words and see what happens to the directory.

    .
    ├── bin
    │   └── words
    ├── pkg
    │   └── darwin_amd64
    └── src
        ├── bitbucket.org
        ├── github.com
        ├── golang.org
        ├── words
        └── wordtest
    

    Now, we can see that we have a words binary created for us(inside the bin directory), and we can run it by invoking ./bin/words.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办