IT story

GOPATH 외부에 디렉토리 xxx에 대한 설치 위치가 없습니다.

hot-time 2020. 6. 25. 07:52
반응형

GOPATH 외부에 디렉토리 xxx에 대한 설치 위치가 없습니다.


~/src/go-statsd-client> echo $GOPATH
/Users/me/gopath
~/src/go-statsd-client> echo $GOROOT
/usr/local/Cellar/go/1.1.1\
~/src/go-statsd-client> go install
go install: no install location for directory /Users/me/src/go-statsd-client outside GOPATH

프로젝트의 구조에 관계없이 항상 동일한 메시지로 실패합니다. Go 빌드는 완벽하게 작동합니다.

여기, 내 것이요 go env

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/me/gopath"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.1.1"
GOTOOLDIR="/usr/local/Cellar/go/1.1.1/pkg/tool/darwin_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common"
CGO_ENABLED="1"

이것은 Mac OSX Mountain Lion에 있으며 homebrew와 함께 설치되었습니다.


에 인수를 제공하지 않으면 go install기본적으로 현재 디렉토리에 패키지를 설치하려고 시도합니다. 현재 디렉토리가의 일부가 아니기 때문에 오류 메시지가 표시되지 않습니다 $GOPATH.

다음 중 하나를 수행 할 수 있습니다.

  • $GOPATH$ HOME ( export GOPATH=$HOME)으로 정의하십시오 .
  • 소스를 현재 $GOPATH( mv ~/src/go-statsd-client /User/me/gopath) 내로 이동하십시오 .

어느 쪽이든 go-statsd-client디렉토리 로 들어가서 go install입력 go install go-statsd-client하면 파일 시스템의 어느 곳에서나 입력 할 수 있습니다. 내장 바이너리는로 들어갑니다 $GOPATH/bin.

관련이없는 제안으로, 이름 충돌을 피하기 위해 패키지 이름을 도메인 이름으로 네임 스페이스하고 싶을 것입니다 (예 : github.com/you/go-statsd-client소스 코드를 보유하고있는 경우).


모든 OS X 사용자 및 이후 사용자의 경우 GOBIN설치시 혼란스러운 메시지가 표시되지 않도록 설정해야합니다.go get

mkdir bin 
export GOBIN=$GOPATH/bin

당신이 사용하는 설치 가서 GOPATH 폴더 외부의 디렉토리에. GOBIN env 변수를 설정하거나 src 폴더를 GOPATH 로 이동 하십시오.

GOPATH/
     bin/
     src/
       go-statsd-client/

추가 정보 : GO 빌드 소스 코드 , 296 행


당신은 설정 모두에 필요 GOPATH하고 GOBIN. (교체하십시오 다음을 수행했는지 확인 ~/go선호와 GOPATH연속적 변화 GOBIN). 에 테스트되었습니다 Ubuntu 16.04 LTS.

export GOPATH=~/go 

mkdir ~/go/bin

export GOBIN=$GOPATH/bin

선택한 답변으로 문제가 해결되지 않았습니다.


선택한 GOPATH 디렉토리 안에 3 개의 디렉토리가 있어야합니다.

GOPATH
     /bin
     /src
       /someProgram
        program.go
       /someLibrary
        library.go
     /pkg

그런 다음 go installsomeProgram (실행 파일을 bin에 저장) 또는 someLibrary (라이브러리를 pkg에 저장)에서 실행합니다.


Windows 에서이 문제가 발생했습니다.

내 문제는 내 %GOPATH%환경 변수가

C:\Users\john\src\goworkspace

대신에

C:\Users\john\src\goworkspace\

끝에 누락 된 후행 슬래시를 추가하면 문제가 해결되었습니다.


가치있는 것을 위해 여기에 Homebrew와 함께 설치 한 후 Atom이있는 Mac에서 잘 작동하는 .bash_profile이 있습니다.

export GOROOT=`go env GOROOT`
export GOPATH=/Users/yy/Projects/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

In my case (OS X) it was because I have set GOPATH to /home/username/go (as per the book) instead of /Users/username/go


I'm on Windows, and I got it by giving command go help gopath to cmd, and read the bold text in the instruction,

that is if code you wnat to install is at ..BaseDir...\SomeProject\src\basic\set, the GOPATH should not be the same location as code, it should be just Base Project DIR: ..BaseDir...\SomeProject.

The GOPATH environment variable lists places to look for Go code. On Unix, the value is a colon-separated string. On Windows, the value is a semicolon-separated string. On Plan 9, the value is a list.

If the environment variable is unset, GOPATH defaults to a subdirectory named "go" in the user's home directory ($HOME/go on Unix, %USERPROFILE%\go on Windows), unless that directory holds a Go distribution. Run "go env GOPATH" to see the current GOPATH.

See https://golang.org/wiki/SettingGOPATH to set a custom GOPATH.

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/" prefix 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. GOBIN must be an absolute path.

Here's an example directory layout:

GOPATH=/home/user/go

/home/user/go/
    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)

..........

if GOPATH has been set to Base Project DIR and still has this problem, in windows you can try to set GOBIN as Base Project DIR\bin or %GOPATH%\bin.


In windows, my cmd window was already open when I set the GOPATH environment variable. First I had to close the cmd and then reopen for it to become effective.


On OSX Mojave 10.14, go is typically installed at /usr/local/go.

Hence, setup these ENVs and you should be good to go.

export GOPATH=/usr/local/go && export GOBIN=/usr/local/go/bin

Also, add these to your bash_profile or zsh_profile if it works.

echo "export GOPATH=/usr/local/go && export GOBIN=/usr/local/go/bin" >> ~/.bash_profile && source ~/.bash_profile


Careful when running

export GOPATH=$HOME

Go assume that your code exists in specific places related to GOPATH. So, instead, you can use docker to run any go command:

docker run -it -v $(pwd):/go/src/github.com/<organization name>/<repository name> golang

And now you can use any golang command, for example:

go test github.com/<organization name>/<repository name> 

The problem is that you are not in the package directory that has the go file with the go main function and go install cannot find the command (go file with go main function) you want to install.

$ cd /path/to/file-with-main-function.go

and then run:

$ go install 

참고URL : https://stackoverflow.com/questions/18149601/go-install-fails-with-error-no-install-location-for-directory-xxx-outside-gopat

반응형