dongxie548548 2013-07-08 10:30
浏览 53
已采纳

Golang:安装目录错误?

I have the error:

go install: no install location for directory /Users/xwilly/Dropbox/go/project/src outside GOPATH 

I'm using go version 1.1 on OS X.

I can build & run but can't install packages.

My environment:

GOPATH=/Users/xwilly/Dropbox/go/project
PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/go/bin:/Users/xwilly/Dropbox/go/project/bin

Project tree:

/Users/xwilly/Dropbox/go/project
bin
pkg
src

I can build without error:

..:src xwilly$ go build test.go 
..:src xwilly$ go install test.go
go install: no install location for directory /Users/xwilly/Dropbox/go/project/src outside GOPATH

Here is a simple example:

xwilly$ cat test.go 
package main

import (
    "fmt"
)

func main() {
    fmt.Println("Bonjour")
}
xwilly$ go run test.go 
Bonjour
xwilly$ go install test.go 
go install: no install location for directory /Users/xwilly/Dropbox/go/project/src/learning outside GOPATH
  • 写回答

1条回答 默认 最新

  • duange051858 2013-07-08 11:37
    关注

    Command go

    GOPATH environment variable

    Each directory listed in GOPATH must have a prescribed structure:

    The src/ directory holds source code. The path below 'src' determines the import path or executable name.

    The pkg/ directory holds installed package objects. As in the Go tree, each target operating system and architecture pair has its own subdirectory of pkg (pkg/GOOS_GOARCH).

    If DIR is a directory listed in the GOPATH, a package with source in DIR/src/foo/bar can be imported as "foo/bar" and has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a".

    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.

    Here's an example directory layout:

    GOPATH=/home/user/gocode
    
    /home/user/gocode/
        src/
            foo/
                bar/               (go code in package bar)
                    x.go
                quux/              (go code in package main)
                    y.go
        bin/
            quux                   (installed command)
        pkg/
            linux_amd64/
                foo/
                    bar.a          (installed package object)
    

    Your directory structure is wrong. You are trying to install a command (package main). It should be in a source directory named after your command. See the quux command above.

    In your case, assume your command is going to be named billy.

    $ mkdir -p /Users/xwilly/Dropbox/go/project/src/billy
    

    which is inside your GOPATH. Move your test.go file to this directory. Run

    $ go install billy
    

    The command billy should, unless you have set GOBIN, be installed in the

    /Users/xwilly/Dropbox/go/project/bin
    

    directory inside your GOPATH, which should be in your PATH.

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

报告相同问题?

悬赏问题

  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致