Install Go on Linux
This guide will help you install Go language on Linux system.
Download Go
First, download the Go installation package suitable for your Linux system from the official website.
Choose the corresponding version based on your system architecture:
linux-amd64- 64-bit x86 architecturelinux-arm64- 64-bit ARM architecturelinux-386- 32-bit x86 architecturelinux-armv6l- ARMv6 architecture
Installation Steps
1. Download the installation package
wget https://go.dev/dl/go1.21.3.linux-amd64.tar.gz2. Delete old version (if any)
sudo rm -rf /usr/local/go3. Extract to /usr/local
sudo tar -C /usr/local -xzf go1.21.3.linux-amd64.tar.gz4. Configure environment variables
Add the following to your ~/.profile or ~/.bashrc file:
export PATH=$PATH:/usr/local/go/bin5. Make environment variables take effect
source ~/.profileOr:
source ~/.bashrc6. Verify installation
go versionIf the installation is successful, you should see output similar to:
go version go1.21.3 linux/amd64Custom Installation Path
If you want to install Go to a custom path, you can:
1. Extract to custom directory
mkdir -p ~/go
tar -C ~/go -xzf go1.21.3.linux-amd64.tar.gz2. Configure environment variables
Add the following to your ~/.profile or ~/.bashrc file:
export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin3. Make environment variables take effect
source ~/.profileConfigure GOPATH
By default, Go uses $HOME/go as the workspace directory. If you want to use a different path, you can set the GOPATH environment variable:
export GOPATH=$HOME/gopath
export PATH=$PATH:$GOPATH/binVerify Installation
Create a simple Go program to verify that the installation is successful:
mkdir -p $HOME/hello
cd $HOME/hello
cat > hello.go << 'EOF'
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
EOF
go run hello.goIf the output is Hello, World!, it means the installation is successful.
Uninstall
If you need to uninstall Go, just delete the installation directory:
sudo rm -rf /usr/local/goThen remove the Go-related environment variables from your ~/.profile or ~/.bashrc file.
Troubleshooting
Permission denied
If you encounter a permission denied error, please use sudo to execute the command:
sudo tar -C /usr/local -xzf go1.21.3.linux-amd64.tar.gzCommand not found
If the go command is not found, please check:
- Whether the PATH environment variable is configured correctly
- Whether the environment variables have taken effect
- Try to restart the terminal or re-login
Version mismatch
If the displayed version does not match the installed version, please check:
- Whether there are multiple Go installations
- Whether the PATH environment variable points to the correct Go installation directory
Next Steps
After installation is complete, you can:
- Visit Go Getting Started Guide to learn Go language basics
- Visit Official Documentation for more detailed documentation
- Visit Go Tour to learn through interactive tutorials
