LoginSignup
36
34

More than 5 years have passed since last update.

MacにIntelliJ IDEAでGolangの開発環境を構築する

Last updated at Posted at 2014-08-03

IntelliJ IDEAとHomebrewでインストールしたGolangで開発環境を構築した時にハマったのでメモ。

環境

GolangをHomebrewでインストール

下記コマンドでGolangをインストール

Terminal
$ brew install go
$ go version
go version go1.3 darwin/amd64

環境変数にGOROOTとGOPATHを追加

.bash_profileもしくは.bashrcGOROOTGOPATH を追加します。
GOROOT に設定するパスは/usr/local/opt/goではなくlibexecまで指定する必要があります。(ここでハマりました)

.bash_profile
export GOROOT=/usr/local/opt/go/libexec
export GOPATH=$HOME/.go

ここを参考に/etc/launchd.confにも同じ値を追加します。
/etc/launchd.confが存在しない場合は、新規作成してください。

launchd.conf
setenv GOROOT /usr/local/opt/go/libexec
setenv GOPATH $HOME/.go

最後に下記コマンドで環境変数を反映します。

Terminal
$ source ~/.bash_profile
$ launchctl < /etc/launchd.conf
$ echo $GOROOT
/usr/local/opt/go/libexec
$ echo $GOPATH
/Users/Yourname/.go

IntelliJ IDEAにGolang環境を構築

  • IntelliJ IDEAのPluginsでGo language support pluginをインストール&再起動
  • [Create New Project]でGoのプロジェクトを作成し、SDK選択画面で[Configure...]からGOROOTを選択
  • プロジェクト作成後にGOROOTGOPATHに関するエラーが表示されなければ構築完了

intellij_golang.png

備考

PhpStormでも同様の手順で環境構築ができます。

謝辞

@abe00makoto さんGOROOTの指定についてご指摘いただき、ありがとうございます。

36
34
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
36
34