Install golang on Linux/Ubuntu, MacOS and Windows

This article provides steps to install golang on Linux/Ubuntu, MacOS and Windows and set up environment.
E
Edtoks2:48 min read

Setting up the Go programming environment involves installing the Go compiler and configuring your system to recognize Go-related commands. Below are step-by-step instructions for installing Go on Linux/Ubuntu, MacOS, and Windows.

Linux/Ubuntu:

  1. Download Go: Open a terminal and run the following command to download the latest stable version of Go:

    sudo apt update
    sudo apt install golang
  2. Set Go Environment Variables: Add the following lines to your shell profile file (e.g., ~/.bashrc or ~/.zshrc):

    export GOPATH=$HOME/go
    export PATH=$PATH:$GOPATH/bin
    export PATH=$PATH:/usr/local/go/bin

    Then, reload your profile:

    source ~/.bashrc   # or source ~/.zshrc
  3. Verify Installation: Verify the Go installation by running:

    go version

    go version

MacOS:

  1. Download Go: Install Go on MacOS using Homebrew. If Homebrew is not installed, you can install it from https://brew.sh/. Once Homebrew is installed, run:

    brew install go
  2. Set Go Environment Variables: Add the following lines to your shell profile file (e.g., ~/.bash_profile or ~/.zshrc):

    export GOPATH=$HOME/go
    export PATH=$PATH:$GOPATH/bin
    export PATH=$PATH:/usr/local/go/bin

    Then, reload your profile:

    source ~/.bash_profile   # or source ~/.zshrc
  3. Verify Installation: Verify the Go installation by running:

    go version

Windows:

  1. Download and Install:

    • Download the MSI installer for Windows from the official Go website: https://golang.org/dl/

    • Run the installer and follow the on-screen instructions.

  2. Set Environment Variables:

    • Right-click on "This PC" or "Computer" and select "Properties."

    • Click on "Advanced system settings."

    • Click on the "Environment Variables..." button.

    • Under "System variables," click on "New" and add a new variable:

      • Variable name: GOPATH

      • Variable value: C:\Users\YourUsername\go (Replace YourUsername with your actual username.)

    • Edit the Path variable and add the following to the end:

      • C:\Go\bin (or the path where Go is installed)

  3. Verify Installation: Open a new Command Prompt and run:

    go version

These steps should help you set up Go on your Linux/Ubuntu, MacOS, or Windows system. Remember to replace any specific paths or usernames with your actual system information. Once installed, you're ready to start writing and running Go programs!

Let's keep in touch!

Subscribe to keep up with latest updates. We promise not to spam you.