Skip to main content

Setup Golang Environment

Install ZSH

https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH

Macos

Most versions of macOS ship zsh by default. Try zsh --version before installing it from Homebrew.

brew install zsh

To set zsh as your default shell, execute the following assuming a default install of Homebrew

Recent macOS versions:

For m1 macs:

chsh -s /opt/homebrew/bin/zsh

For intel macs:

chsh -s /usr/local/bin/zsh

macOS High Sierra and older:

chsh -s /bin/zsh

Ubuntu, Debian & derivatives (Windows 10 WSL | Native Linux kernel with Windows 10 build 1903)

apt install zsh

Install Oh My Zsh

https://ohmyz.sh/#install

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Install go

  1. Download latest golang version from https://go.dev/dl/ to ~/Downloads folder

  2. Install for ubuntu(for other os, please check this document https://go.dev/doc/install)

cd ~/Downloads
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf <your downloaded file>.tar.gz
  1. Setup workspaces

Open ~/.zshrc using command vim ~/.zshrc then append following content to the end.

~/.zshrc
export GOROOT="/usr/local/go"
export GOPATH="$HOME/go-workspace"
export GOBIN="$HOME/go-workspace/bin"
export PATH="$GOROOT/bin:$GOPATH/bin:$PATH"

Setup GOPRIVATE

To access to private go package.

  1. Create a private gitlab token
  2. Create a ~/.netrc file with the following information: Run vim ~/.netrc
~/.netrc
machine <gitlab domain>
login <gitlab_user_name>
password <personal_access_token>

Example:

~/.netrc
machine gitlab.ugaming.io
login sre
password gltk-ahcsassasdsjds
  1. Open ~/.zshrc, add following line
~/zshrc
export GOPRIVATE=<gitlab domain> # gitlab.ugaming.io

Install mykit

go install gitlab.<gitlab_domain>/marketplace/mykit

Example:

go install gitlab.ugaming.io/marketplace/mykit

Install protobuf

mykit setup