Introduction to Installing Go (Golang)
Go, also known as Golang, is a powerful and efficient programming language developed by Google. To start programming in Go, you first need to install it on your system. In this tutorial, we’ll walk you through the steps of installing Go on various operating systems.
Prerequisites
Before you begin, ensure that you have administrative privileges on your system.
Installing Go on Windows
- Download Go Binary:
- Visit the official Go website and download the latest Windows installer (
.msi
file).
- Run Installer:
- Double-click the downloaded
.msi
file to run the installer. - Follow the prompts in the installer, accepting the license agreement and choosing the installation directory.
- Set Environment Variables:
- After installation, add Go’s
bin
directory to your system’sPATH
variable. This step ensures that you can run Go commands from any terminal.bash setx /m PATH "%PATH%;C:\Go\bin"
- Close and reopen any command prompts or terminals for the changes to take effect.
- Verify Installation:
- Open a new command prompt and type the following command to verify that Go has been installed successfully:
bash go version
Installing Go on macOS
- Install Homebrew (Optional):
- If you have Homebrew installed, you can easily install Go using the following command:
bash brew install go
- Download and Install Go Binary:
- Alternatively, you can download the Go package for macOS from the official website.
- Once downloaded, open the
.pkg
file and follow the installation instructions.
- Set Environment Variables:
- After installation, add Go’s
bin
directory to your system’sPATH
variable by adding the following line to your shell profile (e.g.,.bashrc
,.bash_profile
, or.zshrc
):bash export PATH=$PATH:/usr/local/go/bin
- Reload your shell configuration or restart your terminal.
- Verify Installation:
- Open a new terminal window and run the following command to verify that Go has been installed successfully:
bash go version
Installing Go on Linux
- Download and Extract Go Binary:
- Visit the official Go website and download the Linux tarball.
- Extract the tarball to
/usr/local
or any other location of your choice:bash sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
- Set Environment Variables:
- Add Go’s
bin
directory to yourPATH
variable by appending the following line to your shell profile (e.g.,.bashrc
,.bash_profile
, or.zshrc
):bash export PATH=$PATH:/usr/local/go/bin
- Reload your shell configuration or restart your terminal.
- Verify Installation:
- Open a new terminal window and type the following command to verify that Go has been installed successfully:
bash go version
Conclusion
Congratulations! You have successfully installed the Go programming language on your system. You’re now ready to start building powerful and efficient applications using Go.
Remember to refer to the official Go documentation and explore the vast ecosystem of libraries and tools available for Go development.