gpt4 book ai didi

macos - 去安装: directory outside of GOPATH

转载 作者:IT王子 更新时间:2023-10-29 02:24:12 27 4
gpt4 key购买 nike

我刚刚安装了 Go,但我的 go install 无法正常工作。我按照 YouTube 上的教程编写了一个 HelloWorld.go 应用程序,但我一直收到错误消息:

go install: 目录/Users/####/Documents/Dev/go/src/github.com/####/hello 在 GOPATH 之外没有安装位置

这是我的 go env:

GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/####/Documents/Dev/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

在我关注的人的教程中,GOPATH 也被设置为一个文件夹,然后我打算创建文件夹/src/github.com/.....等,然后运行 ​​go install 在包含我的代码的目录中。这是代码,尽管我认为代码不会有太多错误:

package main

import "fmt"

func main() {
fmt.Println("Hello, world!");
}

当我使用我的代码在目录中运行 pwd 命令时,输出如下:/Users/####/Documents/Dev/go/src/github.com/####/hello

当我使用我的代码在目录中运行 echo $GOPATH 命令时,输出如下:/Users/####/Documents/Dev/go

我正在运行 Mac OSX Yosemite。

最佳答案

我可以想到两种可能性:

  1. GOBIN 环境变量

我建议您阅读有关 go 命令的文档,特别是 the section on the GOPATH envvar .引用:

The bin/ directory holds compiled commands. Each command is named for its source directory, but only the final element, not the entire path. That is, the command with source in DIR/src/foo/quux is installed into DIR/bin/quux, not DIR/bin/foo/quux. The foo/ is stripped so that you can add DIR/bin to your PATH to get at the installed commands. If the GOBIN environment variable is set, commands are installed to the directory it names instead of DIR/bin.

Go 很可能会尝试在此处安装您的程序,并遇到权限错误。可能只是一个糟糕的错误信息。无论如何,我不清楚为什么要设置 $GOBIN。要将 go 工具添加到您的 PATH,请直接添加目录:export PATH=/usr/local/go/bin:$PATH

  1. 不区分大小写的文件系统

如果这不起作用,请检查您的主目录的大小写,就像 https://stackoverflow.com/a/27430341 中的问题一样.

关于macos - 去安装: directory outside of GOPATH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27192909/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com