다운로드 할 수없고 $ GOPATH가 설정되지 않았습니다
사용하여 json2csv를 설치하고 싶지만 go get github.com/jehiah/json2csv
이 오류가 발생합니다.
package github.com/jehiah/json2csv: cannot download, $GOPATH not set. For more details see: go help go path
MacOS에서이 문제를 해결하는 방법에 대한 도움이 필요하십니까?
[업데이트 : Go 1.8 기준, GOPATH
기본값은 $HOME/go
이지만 GOPATH
레이아웃 을 이해하고 사용자 정의하는 등의 방법으로 유용 할 수 있습니다 .]
공식 Go 사이트 에서는 GOPATH와 작업 공간 디렉토리를 배치하는 방법에 대해 설명 합니다.
export GOPATH="$HOME/your-workspace-dir/"
-쉘에서 실행 한 다음 추가 ~/.bashrc
하거나 이에 상응하는 기능을 추가 하여 향후에 설정 될 것입니다. 이동에 따라 패키지를 설치합니다 src/
, bin/
그리고 pkg/
, 하위 디렉토리가 있습니다. GitHub에 게시하려는 경우 $GOPATH/src
처럼 자신의 패키지를 아래 어딘가에 배치하고 싶을 것 $GOPATH/src/github.com/myusername/
입니다. 당신은 또한 아마 할 것입니다 export PATH=$PATH:$GOPATH/bin
당신에 .bashrc
아래 그래서 당신은 컴파일 된 실행할 수있는 프로그램 $GOPATH
.
선택적으로 Rob Pike를 통해 bash에 dirs를 CDPATH
더 빨리 cd
패키징 하도록 설정할 수도 export CDPATH=.:$GOPATH/src/github.com:$GOPATH/src/golang.org/x
있습니다 . cd net/html
대신을 입력하면 됩니다 cd $GOPATH/src/golang.org/x/net/html
.
키스 Rarick는 노트 설정할 수있는 GOPATH=$HOME
이동의 넣어 src/
, pkg/
그리고 bin/
바로 홈 디렉토리 아래의 디렉토리. 그것은 좋을 수도 있지만 (예를 들어 이미 $HOME/bin
경로에 있을 수도 있습니다 ) 물론 일부 사람들은 여러 작업 공간 등을 사용합니다.
이 일했다
Ubuntu에서 Go 개발 환경 설정 및 $ GOPATH / $ GOROOT 수정 방법
단계
mkdir ~/go
.bashrc에서 $ GOPATH를 설정하십시오.
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
추출 사용
사용하여 설치했습니다 brew
.
$ brew install go
이 brew 명령을 실행하면 다음 정보가 표시됩니다.
$ brew info go
go: stable 1.4.2 (bottled), HEAD
Go programming environment
https://golang.org
/usr/local/Cellar/go/1.4.2 (4676 files, 158M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/go.rb
==> Options
--with-cc-all
Build with cross-compilers and runtime support for all supported platforms
--with-cc-common
Build with cross-compilers and runtime support for darwin, linux and windows
--without-cgo
Build without cgo
--without-godoc
godoc will not be installed for you
--without-vet
vet will not be installed for you
--HEAD
Install HEAD version
==> Caveats
As of go 1.2, a valid GOPATH is required to use the `go get` command:
https://golang.org/doc/code.html#GOPATH
You may wish to add the GOROOT-based install location to your PATH:
export PATH=$PATH:/usr/local/opt/go/libexec/bin
중요한 부분은 다음과 같습니다.
/usr/local/Cellar/go/1.4.2(4676 파일, 158M) *
내보내기 PATH = $ PATH : / usr / local / opt / go / libexec / bin
GO 환경 설정
GO가 설치된 위치를 보여줍니다. GO 환경을 설정하려면 다음을 수행해야합니다.
$ export PATH=$PATH:/usr/local/opt/go/libexec/bin
$ export GOPATH=/usr/local/opt/go/bin
You can then check using GO to see if it's configured properly:
$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/usr/local/opt/go/bin"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.4.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.4.2/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
Setting up json2csv
Looks good, so lets install json2csv
:
$ go get github.com/jehiah/json2csv
$
What just happened? It installed it. You can check like this:
$ $ ls -l $GOPATH/bin
total 5248
-rwxr-xr-x 1 sammingolelli staff 2686320 Jun 9 12:28 json2csv
OK, so why can't I type json2csv
in my shell? That's because the /bin
directory under $GOPATH
isn't on your $PATH
.
$ type -f json2csv
-bash: type: json2csv: not found
So let's temporarily add it:
$ export PATH=$GOPATH/bin:$PATH
And re-check:
$ type -f json2csv
json2csv is hashed (/usr/local/opt/go/bin/bin/json2csv)
Now it's there:
$ json2csv --help
Usage of json2csv:
-d=",": delimiter used for output values
-i="": /path/to/input.json (optional; default is stdin)
-k=[]: fields to output
-o="": /path/to/output.json (optional; default is stdout)
-p=false: prints header to output
-v=false: verbose output (to stderr)
-version=false: print version string
Add the modifications we've made to $PATH
and $GOPATH
to your $HOME/.bash_profile
to make them persist between reboots.
Watch a Video
In general, I always recommend this official video from Go to get a quick overview on the matter:
http://www.youtube.com/watch?v=XCsL89YtqCs
It's easier to be shown than to be told.
@jwfearn paraphrased the important part of the video:
export GOPATH="${HOME}/gocode"; export PATH="${PATH}:${GOPATH}/bin"; mkdir -p "${GOPATH}"
I found easier to do it like this:
export GOROOT=$HOME/go
export GOPATH=$GOROOT/bin
export PATH=$PATH:$GOPATH
For MAC this worked well for me.
sudo nano /etc/bashrc
and add the below at the end of the file
export PATH=$PATH:/usr/local/opt/go/libexec/bin
export GOPATH=/usr/local/opt/go/bin
This should fix the problem. Try opening a new terminal and echo $GOPATH you should see the correct value.
(for MAC)
I tried all these answers and, for some still unknown reason, none of them worked.
I had to "force feed" the GOPATH by setting the environment variable per every command that required it. For example:
sudo env GOPATH=$HOME/goWorkDirectory go build ...
Even glide
was giving me the GOPATH not set
error. Resolved it, again, by "force feeding": I tried all these answers and, for some still unknown reason, none of them worked.
I had to "force feed" the GOPATH by setting the environment variable per every command that required it.
sudo env GOPATH=$HOME/goWorkDirectory glide install
Hope this helps someone.
Your $GOROOT
should not be set up. You $GOPATH
should be set to $HOME/go
by typing export $GOPATH=$HOME/go
Please type export GOROOT=""
to fix your problem.
Just do export GOPATH="/whatever/you/like/your/GOPATH/to/be"
.
If you run into this problem after having $GOPATH
set up, it may be because you're running it with an unsupported shell. I was using fish
and it did not work, launching it with bash
worked fine.
You can use the "export" solution just like what other guys have suggested. I'd like to provide you with another solution for permanent convenience: you can use any path as GOPATH when running Go commands.
Firstly, you need to download a small tool named gost
: https://github.com/byte16/gost/releases . If you use ubuntu, you can download the linux version(https://github.com/byte16/gost/releases/download/v0.1.0/gost_linux_amd64.tar.gz).
Then you need to run the commands below to unpack it :
$ cd /path/to/your/download/directory
$ tar -xvf gost_linux_amd64.tar.gz
You would get an executable gost
. You can move it to /usr/local/bin
for convenient use:
$ sudo mv gost /usr/local/bin
Run the command below to add the path you want to use as GOPATH into the pathspace gost
maintains. It is required to give the path a name which you would use later.
$ gost add foo /home/foobar/bar # 'foo' is the name and '/home/foobar/bar' is the path
Run any Go command you want in the format:
gost goCommand [-p {pathName}] -- [goFlags...] [goArgs...]
For example, you want to run go get github.com/go-sql-driver/mysql
with /home/foobar/bar
as the GOPATH, just do it as below:
$ gost get -p foo -- github.com/go-sql-driver/mysql # 'foo' is the name you give to the path above.
It would help you to set the GOPATH and run the command. But remember that you have added the path into gost
's pathspace. If you are under any level of subdirectories of /home/foobar/bar
, you can even just run the command below which would do the same thing for short :
$ gost get -- github.com/go-sql-driver/mysql
gost
is a Simple Tool of Go which can help you to manage GOPATHs and run Go commands. For more details about how to use it to run other Go commands, you can just run gost help goCmdName
. For example you want to know more about install
, just type words below in:
$ gost help install
You can also find more details in the README of the project: https://github.com/byte16/gost/blob/master/README.md
Run 'go env' and see where your GOPATH is currently pointing towards. If you change to that directory, your 'go get..etc' command should work.
This problem occured to me in raspberry pi. I had logged in through VNC client The problem persisted despite setting and exporting the GOPATH. Then Ran the "go get" command without sudo and it worked perfectly.
I had to run an application as root (to open a webserver on port 80), this produced the error for me, because the sudo user has a different environment than the normal user, hence GOPATH was not set.
If someone else is having this problem, add -E
to the command, this will preserve the user environment.
sudo -E go run main.go
For more infos see discussion here: Google Groups – GOPATH Problem
참고URL : https://stackoverflow.com/questions/20628918/cannot-download-gopath-not-set
'IT박스' 카테고리의 다른 글
localhost에서 무료 포트 번호를 어떻게 선택합니까? (0) | 2020.06.18 |
---|---|
파이썬 프로그램을 일시 정지하는 올바른 방법 (0) | 2020.06.18 |
파이썬 : 가장 긴 길이로 채워지는 지퍼 같은 기능? (0) | 2020.06.18 |
파이썬에서 람다로 정렬하는 방법 (0) | 2020.06.18 |
파이썬의 주요 방법 이해하기 (0) | 2020.06.17 |