2013-07-08 23 views
21

私はエラーを持っている:Golang:インストールディレクトリエラー?

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

私は&実行を構築することができますが、パッケージをインストールすることはできませんOS Xの

に行くのバージョン1.1を使用しています。

私の環境:

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 

プロジェクトツリー:

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

私はエラーなしで構築することができます:ここで

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

は簡単な例です:

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 
+0

test.goのパッケージ名は何ですか? – thwd

+0

パッケージ名=>パッケージメイン – Xwilly

+0

'package main'をインストールすることはできません。 [Go Goを書く方法](http://golang.org/doc/code.html)を読んでください。 – thwd

答えて

31

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) 

ディレクトリ構造が間違っています。コマンド(package main)をインストールしようとしています。あなたのコマンドの名前に由来するソースディレクトリになければなりません。上記のquuxコマンドを参照してください。

あなたの場合、コマンド名はbillyとすることを前提としています。

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

GOPATHの中にあります。 test.goファイルをこのディレクトリに移動します。あなたがGOBINを設定していない限り、

$ go install billy 

billyがすべきコマンドを実行して、あなたのPATHにする必要がありますあなたのGOPATH、内側

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

ディレクトリにインストールすること。

+1

おかげで、ピーター、明確な説明:)。 – Xwilly

+1

+1大きな説明に感謝します。私はドキュメントの 'gobin'ビットを見逃した – Rippo