Skip to content

Instantly share code, notes, and snippets.

@MuktadirHassan
Created December 8, 2024 16:33
Show Gist options
  • Select an option

  • Save MuktadirHassan/88b05ce9e390006dd11bc674da65e656 to your computer and use it in GitHub Desktop.

Select an option

Save MuktadirHassan/88b05ce9e390006dd11bc674da65e656 to your computer and use it in GitHub Desktop.
Install go directly from go.dev on Linux and correct add to path
#!/bin/bash
# Remove any existing Go installation
sudo rm -rf /usr/local/go
# Download Go
wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gz
# Extract to /usr/local
sudo tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gz
# Create Go workspace directories
mkdir -p $HOME/go/{bin,src,pkg}
# Setup environment variables
SHELL_RC="$HOME/.bashrc"
if [ -f "$HOME/.zshrc" ]; then
SHELL_RC="$HOME/.zshrc"
fi
# Remove any existing Go paths
sed -i '/export GOROOT/d' $SHELL_RC
sed -i '/export GOPATH/d' $SHELL_RC
sed -i '/export PATH=.*go/d' $SHELL_RC
# Add Go paths to shell configuration
echo 'export GOROOT=/usr/local/go' >> $SHELL_RC
echo 'export GOPATH=$HOME/go' >> $SHELL_RC
echo 'export PATH=$GOPATH/bin:$GOROOT/bin:$PATH' >> $SHELL_RC
# Clean up downloaded archive
rm go1.23.4.linux-amd64.tar.gz
# Source the updated configuration
source $SHELL_RC
# Verify installation
go version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment