douxiangshi6568 2018-10-07 09:53
浏览 54

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

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).

my go env output:

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:

package main

import "fmt"

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

but each time i do go install hellp.go, I get:

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/.

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:

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.

  • 写回答

1条回答 默认 最新

  • duanji9677 2018-10-07 10:16
    关注

    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. Try unsetting that variable; things should default to being installed in $GOPATH/bin.

    Also remember that go install takes a package name, not a filename, as its parameter. I'm not clear you can go install something in $GOPATH/src directly, but you can move it into a subdirectory

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退