kukai88

垢 - やったことを残す -

Go 言語の開発/実行環境を整える(macOS 版)

環境

1. macOS 用のパッケージマネージャー homebrew をインストールする

homebrew の公式サイトを確認すると、下のコマンドを実行してインストールする、って記載があります。macOS のターミナルを起動して実行します。

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

引用元:The missing package manager for macOS (or Linux) — Homebrew

2. Go をインストールする

$ brew install go

3. Visual Studio Code に Go 関連のツールをインストールする

Visual Studio Code を起動して、Shift + Command + X を押して、拡張パッケージをインストールする画面に移動します。下の拡張パッケージをインストールしておきます。


次に、Shift + Command + P を押して、コマンド入力欄を表示して、「Go: Install/Update Tools」と入力します。そうすると、Go 関連のツールが表示されるので、全てにチェックを付けて「OK」をクリックします。

Installing 17 tools at /Users/ユーザー名/go/bin
   gocode
   gopkgs
   go-outline
   go-symbols
   ...

Installing github.com/mdempsky/gocode   SUCCESSED
Installing github.com/uudashr/gopkgs/cmd/gopkgs   SUCCESSED
...

試しにコードを書いてみる

下のコードを書いて、デバッグ実行してみます。すると、デバッグコンソールに "Hello World!" と出力されました。

package main

import "fmt"

func main() {
   fmt.Println("Hello World!")
}
API server linstening at: 127.0.0.1:5926
Hello World!