DEV Community

Cover image for Install Go (Golang) on a Linux
pelurunyasar
pelurunyasar

Posted on

Install Go (Golang) on a Linux

To install Go (Golang) on a Linux system, you can follow these steps:

  • Download Go: Open a terminal window and use the wget command to download the Go installation package. You can find the latest version of Go on the official Golang download page.

For example, to download Go version 1.17, you can use:

   wget https://golang.org/dl/go1.17.linux-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode
  • Extract the Archive: After downloading, you need to extract the downloaded archive. Use the tar command to extract it:
   tar -xvf go1.17.linux-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode
  • Move Go: Move the extracted Go directory to a location on your system. Traditionally, it's placed in the /usr/local directory. You'll need superuser (root) privileges for this:
   sudo mv go /usr/local
Enter fullscreen mode Exit fullscreen mode
  • Set Environment Variables: You need to set some environment variables to let your system know where Go is installed and where your Go workspace (where you'll develop your Go programs) is located. Add the following lines to your shell profile configuration file (e.g., ~/.bashrc, ~/.zshrc, or ~/.profile):
   export GOPATH=$HOME/go
   export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
Enter fullscreen mode Exit fullscreen mode

Then, apply the changes to your current shell session:

   source ~/.zshrc ~/.bashrc  # or the appropriate configuration file
Enter fullscreen mode Exit fullscreen mode
  • Verify Installation: You can now verify that Go is installed correctly by opening a new terminal window and typing:
   go version

go1.17 linux/amd64
Enter fullscreen mode Exit fullscreen mode

You should see the installed Go version printed in the output.

go version

Top comments (0)