LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 1 year has passed since last update.

Goの環境構築

Last updated at Posted at 2021-06-23

参考記事

[Go] MacでGo言語環境構築

バージョン管理

brewでインストールされるバージョンはかなり古い

% git clone https://github.com/syndbg/goenv.git ~/.goenv
~/.zshrc
# go settings
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"
export PATH="$GOROOT/bin:$PATH"
export PATH="$PATH:$GOPATH/bin"
% source ~/.zshrc
% goenv -v
goenv 2.0.0beta11

goのインストール

最新版をインストールする

% goenv install -l
% goenv install 1.16.5
% goenv global 1.16.5
% go version         
go version go1.16.5 darwin/amd64

$GOROOTの配下でなくても良いように

% go env -w GO111MODULE=on

Goのコマンド

# コンパイル
% go build fuga hoge.go
# 実行
% ./fuga
# コマンド+実行
% go run hoge.go

アンインストール

下記に加え~/.zshrcの内容も書き換える

% rm -rf ~/.goenv
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