2013-07-08 2 views
21

У меня есть ошибка:Golang: Ошибка установки каталога?

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

Я использую идти версии 1.1 на OS X.

я могу построить & бежать, но не может установить пакеты.

Моя среда:

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'. Прочтите [Как написать код перехода] (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 в этот каталог. Запуск

$ go install billy 

Команда billy должен, если вы не установили GOBIN быть установлен в каталоге

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

внутри вашего GOPATH, которые должны быть в вашем PATH.

+1

Спасибо, Питер, за ясное объяснение :). – Xwilly

+1

+1 спасибо за отличное объяснение. Я пропустил бит gobin в документах – Rippo

Смежные вопросы