LoginSignup
19
13

More than 5 years have passed since last update.

anyenvでgoenvをインストールし、Visual studio codeでGO言語を使用して開発する環境を整える

Last updated at Posted at 2018-08-03

環境

  • OS Sierra
  • Visual Studio Code 1.25.1 (1.25.1)
  • ※前提として最新のanyenvのインストールが完了しているとします
  • [参考]https://github.com/riywo/anyenv

goenvのインストール

anyenv install goenv
exec $SHELL -l
goenv install -l //インストールできるGoのバージョンが表示されます
goenv install 1.10.3 //バージョンは適宜修正してください 
goenv global 1.10.3 //今回はグローバルにインストールします

GOPATHの設定

  • シェルの設定ファイルに以下を追記(~/.bashrcや~/.zshrcなど)
    • GOPATHのディレクトリは適宜修正してください
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$PATH

Visual Studio Codeの設定

  • 拡張機能よりGoをインストール(Gopherのアイコンが付いているもの)
    • Visual Studio Codeをリロードして拡張機能を有効化してください
  • Code->基本設定->設定よりsettings.jsonを開く
  • 以下を右側のエディタに貼り付け
    • Visual Studio Codeのデフォルトのシェルがbashになっていたので一番上の行でzshに変更しています
    • go.gopathには「GOPATHの設定」で設定したパスを設定します
settings.json
"terminal.integrated.shell.osx": "/usr/local/bin/zsh",
"go.gopath": "/Users/ユーザ名/go",
"go.goroot":"/Users/ユーザ名/.anyenv/envs/goenv/versions/1.10.3"
  • Visual Studio Codeを再起動

その他

19
13
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
19
13