Golang environment construction

This article is a memorandum for Go beginners.

environment

OS: Mac Catalina Shell: Zsh

Install Go

Install Go with homebrew

brew install go 

Check if the installation is completed (check the version as well)

go version
#Output result example) go version go1.15.2 darwin/amd64

Check the environment variable $ GOROOT (Go installation destination)

go env GOROOT
#Output result example)/usr/local/Cellar/go/1.15.2/libexec

Check the environment variable $ GOPATH

go env GOPATH
#Output result example)/Users/Username/go

ls $(go env GOPATH)
#Output result example) ls: /Users/Username/go: No such file or directory

Go preferences

Package installation (gore)

go get github.com/motemen/gore/cmd/gore

Check GOPATH and check package

ls $(go env GOPATH)
#Output result) bin/ src/

Set GOPATH (make installed packages available as commands)

vim ~/.zshrc

Add the following contents to the end of ~ / .zshrc

~/.zshrc


"Golang path settings
export GOPATH=$(go env GOPATH)
export PATH=$PATH:$GOPATH/bin

Reload ~ / .zshrc after saving and closing

source ~/.zshrc

Check if the installed package is available on the command line

gore can execute go interactively like ruby's irb

gore -autoimport
 gore>
 gore> fmt.Println(Hello World)
 Hello World
 12
 <nil>

↑ 12 bytes are output, meaning that there was no error End with ctrl + d

Install extension tools that make gore more convenient

Allow for code completion, output highlighting, API documentation, etc.

go get github.com/mdempsky/gocode
go get github.com/k0kubun/pp

Project management tool settings

Install the project management tool * ghq *

brew install ghq
Check ghq (Display a list of Go packages (projects) installed on your device)
ghq list

#Output result example)
# golang.org/x/tools
# golang.org/x/xerrors
# golang.org/x/sys
# golang.org/x/text
# golang.org/x/mod
# github.com/peterh/liner
# github.com/k0kubun/pp
# github.com/motemen/gore
# github.com/motemen/go-quickfix
# github.com/mdempsky/gocode
# github.com/mattn/go-isatty
# github.com/mattn/go-runewidth
# github.com/mattn/go-colorable
Specify the directory to get the source with ghq
git config --global ghq.root $GOPATH/src

ghq seems to be hitting the git command behind the scenes.

Other details will be dealt with as needed.

Recommended Posts

Golang environment construction
Golang environment construction [goenv]
Django environment construction
DeepIE3D environment construction
Emacs-based environment construction
Linux environment construction
Python environment construction
Environment construction (python)
django environment construction
CodeIgniter environment construction
python environment construction
Python environment construction
python environment construction
Word2vec environment construction
Environment construction: GCP + Docker
python windows environment construction
Go language environment construction
homebrew python environment construction
PyData related environment construction
Anaconda-4.2.0-python3 environment construction (Mac)
Python development environment construction
YOLO v4 environment construction ①
pyenv + fish environment construction
python2.7 development environment construction
BigGorilla environment construction memo
grip environment construction onCentOS6.5
Anaconda environment construction memo
Mac environment construction Python
Pyxel environment construction (Mac)
Python environment construction @ Win7
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
Python + Anaconda + Pycharm environment construction
About Linux environment construction (CentOS)
PyTorch C ++ (LibTorch) environment construction
Anaconda environment construction on CentOS7
Django development environment construction memo
First LAMP environment construction (Linux)
Environment
CI environment construction ~ Python edition ~
[Memo] Construction of cygwin environment
ML environment construction with Miniconda
Anaconda3 python environment construction procedure
Docker + Django + React environment construction
Anaconda3 × Pycharm environment construction memo
Python3 environment construction (for beginners)
Python environment construction and TensorFlow
NumPy and matplotlib environment construction
Machine learning environment construction macbook 2021
Python environment construction under Windows7 environment
[MEMO] [Development environment construction] Python
Ubuntu14.04 + GPU + TensorFlow environment construction
[Tensorflow] Tensorflow environment construction on Windows 10
Environment construction, Build -Go edition-
django project development environment construction
Linux environment construction (on WSL environment)
Environment construction of python2 & 3 (OSX)
[MEMO] [Development environment construction] wine
Ansible environment construction For Mac
Golang + Gin + Docker hot reload, VS Code debugging environment construction
DL Laravel environment construction method (Linux)
Environment construction of python and opencv