2013-07-08 21 views
21

devo l'errore:Golang: errore nella directory di installazione?

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

sto usando la versione 1.1 andare su OS X.

posso costruire & periodo, ma non riesco a installare i pacchetti.

Il mio ambiente:

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 

albero del progetto:

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

posso costruire senza errori:

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

Ecco un semplice esempio:

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

qual è il nome del pacchetto in test.go? – thwd

+0

il nome del pacchetto è => pacchetto principale – Xwilly

+0

Non è possibile installare 'pacchetto principale'. Leggi [Come scrivere Go Codice] (http://golang.org/doc/code.html). – thwd

risposta

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) 

La struttura della directory è errata. Stai tentando di installare un comando (package main). Dovrebbe essere in una directory di origine chiamata dopo il comando. Vedi il comando quux qui sopra.

Nel tuo caso, supponi che il tuo comando sia denominato billy.

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

che si trova all'interno del GOPATH. Sposta il tuo file test.go in questa directory. Eseguire

$ go install billy 

Il comando billy dovrebbe, a meno che non si è impostato GOBIN, essere installato nella directory

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

all'interno del vostro GOPATH, che dovrebbe essere nel vostro PATH.

+1

Grazie Peter, per la chiara spiegazione :). – Xwilly

+1

+1 grazie per la grande spiegazione. Ho perso il bit 'gobin' nei documenti – Rippo

Problemi correlati