LoginSignup
5
4

More than 3 years have passed since last update.

【Go1.14】GOPATHが$HOME/goから変わらない時にやった事

Last updated at Posted at 2020-05-27

前提

  • 私のPC & OS
    image.png

  • goのversion

~ » go version
go version go1.14.3 darwin/amd64

困った事

  • 環境変数を上書きしてPATHを設定しても、GOPATHだけがデフォルトから変わらない。
export GOPATH=/Users/myname/workspace/go
export GOROOT=/Users/myname/sdk/go1.14.3

export PATH=$PATH:"$GOROOT/bin"
export PATH=$PATH:"$GOPATH/bin"
~ » go env GOPATH
/Users/myname/go

やったこと

  • ヘルプコマンドから公式Wikiに辿り着く
~ » go help gopath
The Go path is used to resolve import statements.
It is implemented by and documented in the go/build package.

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.

省略
  • Go1.13との記載があるコマンドを実行 image.png
go env -w GOPATH=$HOME/go
  • 無事に変更された
~ » go env GOPATH
/Users/myname/workspace/go

後書き

Go1.13から新しい設定手順ができたのかな?
色々調べて過去の情報やちょっと違う手順で少し詰まってしまいました。
公式の手順に従うのが一番最速ですね。

参考記事

SettingGOPATH - golang.org

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4