How to Install Go (Golang)


Back to All Posts

Go, also known as Golang, is a programming language developed by Google that is widely used for building fast and efficient applications. Here are the steps to install Go on different operating systems.

System Requirements

Before starting the installation, make sure your system meets the following minimum requirements:

  • Windows: Windows 7 or later
  • macOS: macOS 10.10 or later
  • Linux: Linux kernel 2.6.23 or later

Step 1: Download the Go Installer

You can download the latest version of Go from the official Go website at https://golang.org/dl/. Choose the installer that matches your operating system:

  • Windows: Download the .msi file
  • macOS: Download the .pkg file
  • Linux: Download the .tar.gz file

Step 2: Install Go

Install on Windows

  1. Run the downloaded .msi file.

  2. Follow the on-screen installation instructions.

  3. Once the installation is complete, open Command Prompt and type the following command to verify the installation:

    go version
    

    If Go is installed successfully, you will see the installed version of Go.

Install on macOS

  1. Open the downloaded .pkg file.

  2. Follow the on-screen installation instructions.

  3. Once complete, open Terminal and type the following command to verify the installation:

    go version
    

    If Go is installed successfully, you will see the installed version of Go.

Install on Linux

  1. Extract the downloaded .tar.gz file to the /usr/local directory using the following command:

    sudo tar -C /usr/local -xzf go<version>.linux-amd64.tar.gz
    
  2. Add /usr/local/go/bin to the PATH variable in your .profile or .bashrc file:

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

    Then reload the .profile or .bashrc file:

    source ~/.profile
    
  3. Verify the installation by typing the following command:

    go version
    

    If Go is installed successfully, you will see the installed version of Go.

Step 3: Set Up Go Workspace

After installing Go, you need to set up your workspace. By default, the Go workspace is located at ~/go on Linux and macOS, or C:\Users\<username>\go on Windows.

  1. Create the workspace directory if it does not already exist:

    mkdir -p ~/go/{bin,pkg,src}
    
  2. Set GOPATH to point to your workspace directory:

    export GOPATH=~/go
    

    Also, add it to the PATH variable:

    export PATH=$PATH:$GOPATH/bin
    

Step 4: Run Your First Go Program

After Go is installed, you can create and run your first Go program:

  1. Create a new directory inside src:

    mkdir -p ~/go/src/hello
    
  2. Create a hello.go file with the following content:

    package main
    
    import "fmt"
    
    func main() {
        fmt.Println("Hello, World!")
    }
    
  3. Run the program:

    go run hello.go
    

    You will see the output "Hello, World!" in the terminal.

Now Go has been successfully installed on your system, and you have run your first Go program. You are ready to start learning and developing applications with Go. Happy coding!