Installing the Go Programming Language From Scratch
Language
- unknown
by James (Golang Project Structure Admin)
Installing the Go programming language for the first time is really easy, regardless of what operating system or processor architecture your computer is running.
![](https://golangprojectstructure.com/wp-content/uploads/2023/01/gopher-small-mammal-animal-illustration-512x328.jpg)
It’s particularly straightforward to install Go on Windows or MacOS machines, but Linux users won’t find the process unnecessarily difficult either, especially if they’re using a package manager.
Table of Contents
Where to Find Go
You should always be able download the latest stable release of Go from the programming language’s official website.
There are versions available for all three of the major operating systems: Linux, MacOS and Windows.
Installing the Go Programming Language on Windows
Although the earliest versions of the Go compiler were designed to run exclusively on UNIX-based operating systems, the programming language now has excellent native support for Windows.
You can download an MSI file from Go’s official website, which will provide an easy-to-run installer program. This will put the necessary files onto your machine.
By default, the installer will place the Go files into a subdirectory of C:\Program Files
(for 64-bit installations) or C:\Program Files (x86)
(for 32-bit installations).
Installing the Go Programming Language on MacOS
Just as an MSI file can be downloaded on Windows to run an official installer program, the Go website also provides PKG files that provide the equivalent installers for MacOS.
Make sure that you choose the appropriate package based on your Mac’s operating system version and architecture, then when you run the installer, you can simply follow the on-screen instructions to install Go.
Installing the Go Programming Language on Linux
Many Linux distributions will have Go available to install via their package manager.
For example, on Debian-based Linux systems, we can use the following command to install the Go programming language:
sudo apt-get install golang-go
Likewise, the following command can be used to install Go on Arch Linux:
sudo pacman -S go
Performing a Manual Install of Go on Linux
On the other hand, if we want to install a specific version of Go, we can install it manually from a binary file.
Once we’ve found the URL for the appropriate file by visiting the Go website in a web browser, we can download it to our machine using the wget
command, like so:
wget -L "https://go.dev/dl/go1.20.src.tar.gz"
Then we can extract the tarball:
tar -xf "go${VERSION}.linux-${ARCH}.tar.gz"
This should provide us with a newly extracted subdirectory of the current directory called go
.
The final step involves setting the correct permissions on the subdirectory and moving it to a more suitable location:
sudo chown -R root:root ./go
sudo mv -v ./go /usr/local
Setting the Path Environment Variable on Linux
Finally, we can edit either the .bash_profile or .profile file located in our home directory, adding the following line to the end of one of the files:
export PATH=$PATH:/usr/local/go/bin
This ensures that our system will be able to find the Go binary files that we’ve just installed.
Verifying That the Installation Has Worked
Start by opening a command-line terminal. There are various ways to do this in Linux or MacOS, but if you’re running Windows, click the Start menu, type "cmd"
into the search box and press Enter.
When the terminal window is open, enter the following line as a command and press Enter to run it:
go version
Since I’m currently running version 1.19 of the Go programming language on a 64-bit Windows machine, when I run the command above, it produces the following output:
go version go1.19.4 windows/amd64
If the command will not run on your machine, perhaps the Go programming language hasn’t been properly installed and you’ll need to troubleshoot it.