dsklfsdlkf1232 2015-07-20 04:10
浏览 178
已采纳

转到:“ stat hello.go:没有此类文件或目录”

Just installed Go on Mac OS X, Yosemite Version 10.10.3, as explained in the Getting Started page of the official website:

Mac OS X package installer

Download the package file, open it, and follow the prompts to install the Go tools. The package installs the Go distribution to /usr/local/go.

The package should put the /usr/local/go/bin directory in your PATH environment variable. You may need to restart any open Terminal sessions for the change to take effect.

I am now in the Test your installation section, which states:

Check that Go is installed correctly by building a simple program, as follows.

Create a file named hello.go and put the following program in it:

package main

import "fmt"

func main() {
    fmt.Printf("hello, world
") }

Then run it with the go tool:

$ go run hello.go
hello, world

If you see the "hello, world" message then your Go installation is working.

So, I created a hello.go file and, since I could not (ie: did not know how to) access the /usr/local/go/bin directory, I saved it on my desktop.

Obviously, I got the following error message:

stat hello.go: no such file or directory

So, where should I save my Go files to be able to run them?

UPDATE: after some research, I stumbled upond this video, explaining how to set the GOPATH.

If I want my Go workspace to be in user/code/go, how should I write my export GOPATH= command?

  • 写回答

1条回答 默认 最新

  • dongzhong9055 2015-07-20 04:51
    关注

    Following the explanation of Andrew Gerrand in Writing, building, installing, and testing Go code, I configured my Go workspace as follows:

    1. Create workspace

    First, since I want my Go code to be in my_user_name/code/go, I started by creating the corresponding folder:

    $ cd code
    $ mkdir go
    

    2. Setup GOPATH

    Then I configured the GOPATH:

    $ cd
    $ export GOPATH=$HOME/code/go
    $ cd code/go
    

    3. Add files to workspace

    Last, I manually (through the Finder) moved my hello.go file into the workspace and ran:

    $ go run hello.go
    

    Worked like a charm.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败