Sling Academy
Home/Golang/How to upgrade/ downgrade Go to a specific version

How to upgrade/ downgrade Go to a specific version

Last updated: November 26, 2024

Introduction

Golang, often referred to as Go, is a popular statically typed, compiled programming language designed by Google. There are many reasons you might want to upgrade or downgrade your Go version - perhaps you need a specific feature or a bug fix introduced in a later version, or maybe you need to revert to an earlier version due to compatibility issues with existing code.

Prerequisites

Before you start, ensure you have the following:

  • Access to a terminal or command prompt
  • Administrator or appropriate permissions to modify software installations on your system
  • The official Go installation guide for reference

Checking Your Current Version

First, check the version of Go currently installed on your system to know your starting point. Open your terminal and type:

go version

This will display the current Go version installed, for example: go version go1.16 darwin/amd64.

Upgrading or Downgrading Go

Follow these steps to upgrade or downgrade your Go installation:

Using Homebrew (macOS)

If you're on macOS and using Homebrew, it's effortless to manage your Go versions:

brew unlink go
brew install [email protected]

To use this specific version, you need to link it:

brew link [email protected] --force

Replace 1.14 with your desired version number.

Using Windows

For Windows users, the upgrade or downgrade process involves steps similar to installing Go for the first time:

  1. Uninstall the current version via Control Panel > Programs > Programs and Features.
  2. Visit the Go download page.
  3. Select your target version, download the installer for Windows, and run it.

Using Linux

Linux users can switch Go versions by downloading and installing from binaries:

sudo rm -rf /usr/local/go
curl -OL https://golang.org/dl/go1.14.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.14.linux-amd64.tar.gz

Again, replace 1.14 and amd64 with your target version and architecture.

Post-installation Checks

After installation, verify that your Go path is correctly set by opening your terminal and typing:

go env

Confirm the variable GOROOT is set to the Go directory you installed to, typically /usr/local/go.

Finally, confirm your specified version has been successfully installed:

go version

This should display your desired version.

Conclusion

Switching between versions of Go is generally a straightforward process, especially with tools such as Homebrew for macOS. Ensure that any time you make a change, both your GOPATH and GOROOT are verified to avoid any conflicting errors. Regular checks on dependencies when changing Go versions also help ensure your development environment continues to run smoothly.

Next Article: How to use multiple versions of Go on a computer

Previous Article: How to check the current version of Go

Series: Getting Started with Golang

Golang

Related Articles

You May Also Like

  • How to remove HTML tags in a string in Go
  • How to remove special characters in a string in Go
  • How to remove consecutive whitespace in a string in Go
  • How to count words and characters in a string in Go
  • Relative imports in Go: Tutorial & Examples
  • How to run Python code with Go
  • How to generate slug from title in Go
  • How to create an XML sitemap in Go
  • How to redirect in Go (301, 302, etc)
  • Using Go with MongoDB: CRUD example
  • Auto deploy Go apps with CI/ CD and GitHub Actions
  • Fixing Go error: method redeclared with different receiver type
  • Fixing Go error: copy argument must have slice type
  • Fixing Go error: attempted to use nil slice
  • Fixing Go error: assignment to constant variable
  • Fixing Go error: cannot compare X (type Y) with Z (type W)
  • Fixing Go error: method has pointer receiver, not called with pointer
  • Fixing Go error: assignment mismatch: X variables but Y values
  • Fixing Go error: array index must be non-negative integer constant