Installing GO on WSL2 and MacOS
프로젝트를 진행하면서 GO를 이용한 Server 구축을 공부해 보고자 GO syntax 정리에 앞서 설치와 환경설정을 먼저 다뤄본다. WSL2 와 MacOS 에 설치를 할 것이며 두 OS 모두 oh my zsh 를 사용하고 있다.
Test GO Online
Download Link
- See Setup on WSL2 for Install Binary Distribution
Setup on WSL2
- Copy link address of the GO Linux version
Download the latest version and extract in the current directory
1 2
$ wget https://golang.org/dl/go1.16.3.linux-amd64.tar.gz $ sudo tar -svf go1.16.3.linux-amd64.tar.gz
tar
: stores/extracts files from the archivex
: extracts the file from targetv
: verbosly list files processf
: use archive file
Move the extracted go directory to /usr/local
1
$ sudo mv go /usr/local
Set environment variables
Open Home directory
1 2
$ cd $ explorer.exe .
Add global variables on
.bashsrc
or.zhsrc
1 2 3 4
# Go Global variables export GOROOT=/usr/local/go export GOPATH=$HOME/go export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
Setup on Mac
Open the package file you downloaded and follow the prompts to install Go.
The package installs the Go distribution to /usr/local/go. The package should put the /usr/local/go/bin directory in your PATH environment variable. You may need to restart any open Terminal sessions for the change to take effect.
Verify that you’ve installed Go by opening a command prompt and typing the following command:
1
$ go version
Confirm that the command prints the installed version of Go.