Home  Golang   How to inst ...

How to install Go (Golang) on various operating systems

Installing Go (Golang) on various operating systems is straightforward. Here are the general steps for installing Go on different OS platforms:

Installing Go on Linux

  1. Using Package Manager (recommended for most Linux distributions):

    • Open your terminal.
    • Update your package index: sudo apt update (for Debian/Ubuntu) or equivalent for other distributions.
    • Install Go using the package manager: sudo apt install golang (for Debian/Ubuntu).
  2. Using Binary Distribution:

    • Download the Go binary distribution from the official website: https://golang.org/dl/
    • Extract the downloaded archive to /usr/local or any directory of your choice.
      sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
      
    • Add Go binaries to your PATH by adding the following line to your ~/.profile or ~/.bashrc:
      export PATH=$PATH:/usr/local/go/bin
      
    • Reload the shell configuration: source ~/.profile or source ~/.bashrc.
  3. Verifying Installation:

    • Verify Go installation by running go version in the terminal.

Installing Go on macOS

  1. Using Homebrew (recommended):

    • Open your terminal.
    • Install Go using Homebrew:
      brew install golang
      
  2. Using Binary Distribution:

    • Download the Go binary distribution from the official website: https://golang.org/dl/
    • Mount the downloaded disk image and drag the go folder to /usr/local or any directory of your choice.
    • Add Go binaries to your PATH by adding the following line to your ~/.profile or ~/.bash_profile:
      export PATH=$PATH:/usr/local/go/bin
      
    • Reload the shell configuration: source ~/.profile or source ~/.bash_profile.
  3. Verifying Installation:

    • Verify Go installation by running go version in the terminal.

Installing Go on Windows

  1. Using MSI Installer (recommended):

    • Download the MSI installer from the official website: https://golang.org/dl/
    • Run the installer and follow the prompts to complete the installation.
  2. Using Archive (zip) Distribution:

    • Download the zip archive from the official website.
    • Extract the contents to C:\Go or any directory of your choice.
    • Add C:\Go\bin to the Path environment variable:
      • Right-click on This PC -> Properties -> Advanced system settings -> Environment Variables....
      • Under System Variables, find Path, click Edit..., and add C:\Go\bin to the list.
    • Open a new Command Prompt (cmd) and verify Go installation by running go version.
  3. Verifying Installation:

    • Verify Go installation by running go version in the Command Prompt.

Setting Up GOPATH (Optional but recommended)

This setup allows you to manage and run your Go projects effectively. After installation, you can start developing Go applications and use tools like go build, go run, and go get to manage dependencies.

Published on: Jun 19, 2024, 11:19 PM  
 

Comments

Add your comment