Post

Installing GO on WSL2 and MacOS

프로젝트를 진행하면서 GO를 이용한 Server 구축을 공부해 보고자 GO syntax 정리에 앞서 설치와 환경설정을 먼저 다뤄본다. WSL2 와 MacOS 에 설치를 할 것이며 두 OS 모두 oh my zsh 를 사용하고 있다.

Test GO Online

Test GO from online

Download GO from this link

  • See Setup on WSL2 for Install Binary Distribution

Setup on WSL2

  1. Copy link address of the GO Linux version
  2. 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 archive
    • x: extracts the file from target
    • v: verbosly list files process
    • f: use archive file
  3. Move the extracted go directory to /usr/local

    1
    
    $ sudo mv go /usr/local
    
  4. 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

  1. 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.

  2. Verify that you’ve installed Go by opening a command prompt and typing the following command:

    1
    
    $ go version
    
  3. Confirm that the command prints the installed version of Go.

Reference

This post is licensed under CC BY 4.0 by the author.