3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

$HOMEにgoをインストールしてからgo getが使えるようになるまで

Posted at

homebrewのinstall先が$HOMEだったせいでハマった

# homebrewでinstall
brew install go
# goはここに入った
$HOME/homebrew/opt/go/libexec/bin/go
  • カスタムインストールしたのでGOROOTの設定が必要
  • GOPATHはどこにインストールしても必要
.zshrc
# GOPATH, GOROOT
export GOPATH=$HOME/go
export GOROOT=$HOME/homebrew/opt/go/libexec

export PATH="$GOPATH/bin:$PATH"
export PATH="$GOROOT/bin:$PATH"
  • GOROOT=$HOME/homebrew/opt/go/ではダメだった
    • go getしたパッケージが依存してる標準パッケージを探せないらしい。

公式documentには書いてあった

Getting Started - The Go Programming Language
ググってhitした記事のやり方真似て時間ロスするより、最初から公式のdocument読めばよかった

Installing to a custom location

The Go binary distributions assume they will be installed in /usr/local/go (or c:\Go under Windows), but it is possible to install the Go tools to a different location. In this case you must set the GOROOT environment variable to point to the directory in which it was installed.

For example, if you installed Go to your home directory you should add the following commands to $HOME/.profile:

export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin
Note: GOROOT must be set only when installing to a custom location.

3
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?