donglu3087 2016-03-19 05:42
浏览 25

去不跑世界你好例子

I am installing go in Ubuntu 14.04 and believe I have my GOPATH$ set right and can't seem to run this go install hello.go file. I got rid of any path errors that I encountered first, but I still am not seeing a successful run

Go is installed in /etc/go

$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/etc/go/packages"
GORACE=""
GOROOT="/etc/go"
GOTOOLDIR="/etc/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

And here I made the file, edited via nano to copy the hello world example, but when I run it, nothing happens...

$ mkdir -p $GOPATH/src/github.com/hackg
$ nano $GOPATH/src/github.com/hackg/hello/hello.go
$ go install github.com/hackg/hello
$

QUESTION - it is supposed to display hello world there, proving Go is building files properly, but all I get is a fresh terminal prompt ready for a new command, no HELLO WORLD

I tried looking at other stackoverflow posts with no luck - ex Go, Golang : does not make sense that I have to have files before import

  • 写回答

4条回答 默认 最新

  • dongmei8511 2016-03-19 05:50
    关注

    No, that command won't run your program; go install just made a binary you can run with $GOPATH/bin/hello. You can add to your ~/.bashrc or equivalent the line export PATH=$GOPATH/bin:$PATH, and open a new shell (like by closing and reopening your terminal program), so you can call it with just hello. go running the file would compile and run, but it's reasonable to start with go install because that's what you're going to use for "real" programs as opposed to quick tests.

    (Sounds like you're on the right track with a GOPATH and all, but for setting up a Go environment generally you might find this question helpful.)

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用