简体   繁体   English

这是有效的Go路径配置吗?

[英]Is this a valid Go path config?

I've placed my path variables as follows: 我将路径变量放置如下:

export GOROOT=/usr/local/go
export GOPATH=$HOME/Professional/Sch/Fabric/go
export GOBIN=/usr/local/go/bin
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

I've placed these lines in both ~/.profile and ~/.bashrc and sourced them both (not sure which of them is taking effect). 我已经将这些行同时放在〜/ .profile和〜/ .bashrc中,并同时获得了它们的来源(不确定它们中的哪个正在生效)。

my go env output: 我的go env输出:

GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/home/deepak/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/deepak/Professional/Sch/Fabric/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build653871525=/tmp/go-build -gno-record-gcc-switches"

I've placed the following code in $HOME/Professional/Sch/Fabric/go/hellp.go: 我将以下代码放在$ HOME / Professional / Sch / Fabric / go / hellp.go中:

package main

import "fmt"

func main() {
    fmt.Printf("Hello, World!\n")
}

but each time i do go install hellp.go , I get: 但是每次我go install hellp.go ,我都会得到:

go install command-line-arguments: open /usr/local/go/bin/hellp: permission denied

which is strange because go version returns a go version go1.10.4 linux/amd64 , and I'm not sure why its trying to reference /usr/local/go/bin/hellp as there is no 'hellp' file there, its a sample file I created at $HOME/Professional/Sch/Fabric/go/ . 这很奇怪,因为go version返回go version go1.10.4 linux/amd64 ,我不确定为什么它尝试引用/usr/local/go/bin/hellp因为那里没有'hellp'文件,它是我在$HOME/Professional/Sch/Fabric/go/创建的示例文件。

I'm not sure which directory permission is missing, but I've tried: 我不确定缺少哪个目录权限,但是我尝试了:

  201  sudo chmod -R 777 ~/Professional/Sch/Fabric
  202  go install hellp.go 
  203  sudo chmod -R 777 ~/Professional/Sch/Fabric/go/hellp.go 
  204  go install hellp.go 
  205  sudo chmod -R 777 ~

My uname -a output: 我的uname -a输出:

Linux instance-1 4.9.0-8-amd64 #1 SMP Debian 4.9.110-3+deb9u4 (2018-08-21) x86_64 GNU/Linux

I'm trying to install HyperLedger Fabric for which Go is a prerequisite, and clearly go version output shows its successfully installed, however, I'm not sure where or how it needs to be configured to test and use it. 我正在尝试安装必须安装Go的HyperLedger Fabric,并且显然go version输出显示成功安装了它,但是,我不确定在何处或如何配置它来测试和使用它。

Your GOBIN setting is telling go install to try to install compiled binaries into a system-global directory you don't have permission to write to. 您的GOBIN设置告诉go install尝试将编译的二进制文件go install到您GOBIN写入的系统全局目录中。 Try unsetting that variable; 尝试取消设置该变量; things should default to being installed in $GOPATH/bin . 东西应该默认安装在$GOPATH/bin

Also remember that go install takes a package name , not a filename, as its parameter. 还要记住, go install将软件包名称 (而不是文件名)作为其参数。 I'm not clear you can go install something in $GOPATH/src directly, but you can move it into a subdirectory 我不清楚您可以直接在$GOPATH/src go install某些内容,但可以将其移至子目录中

unset $GOBIN    
cd $GOPATH/src
mkdir github.com/myname/helpp
mv helpp.go github.com/myname/helpp
go install github.com/myname/helpp
$GOPATH/bin/helpp  # uses the name of the package directory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM