Skip to content

Commit 07ffc1c

Browse files
committed
blowfish theme update. update go installer script post
1 parent a4000d6 commit 07ffc1c

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

content/posts/go-installer.md

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,39 @@ author: "Kapil Agrawal"
66
comments: false
77
---
88

9-
I wrote a super simple shell script to install Go on a linux system to get a consistent Go environment for all users. I often use this script when I need Go installed on a remote development VM specialy when working on projects that require x86-64 architecture.
9+
I asked our LLM overlords to generate a simple shell script to install Go on a linux system so as to get a consistent development environment regardless of the underlying OS architecture (amd64 vs. arm) I am working on. By default it installs the latest release. To install a specific go version pass it as a cli argument when running the script.
1010

1111
```sh
1212
#!/bin/bash
1313

14-
set -e # Exit on error
15-
set -o pipefail # Catch errors in pipelines
14+
set -e
15+
set -o pipefail
1616

17-
VERSION=${1:-"1.24.1"}
18-
ARCH="linux-amd64"
17+
# Detect architecture
18+
ARCH_RAW=$(uname -m)
19+
case "$ARCH_RAW" in
20+
x86_64) GO_ARCH="amd64" ;;
21+
aarch64 | arm64) GO_ARCH="arm64" ;;
22+
*)
23+
echo "❌ Unsupported architecture: $ARCH_RAW" >&2
24+
exit 1
25+
;;
26+
esac
27+
28+
# Get version (default: latest)
29+
if [ -n "$1" ]; then
30+
VERSION="$1"
31+
else
32+
echo "📦 Fetching latest Go version..."
33+
VERSION=$(curl -s https://go.dev/VERSION?m=text | head -n 1 | sed 's/go//')
34+
fi
35+
36+
ARCH="linux-${GO_ARCH}"
1937
GO_TARBALL="go${VERSION}.${ARCH}.tar.gz"
2038
GO_URL="https://go.dev/dl/${GO_TARBALL}"
2139
INSTALL_DIR="/usr/local/go"
2240

41+
# Root check
2342
if [ "$(id -u)" -ne 0 ]; then
2443
echo "This script must be run as root or with sudo." >&2
2544
exit 1
@@ -34,32 +53,26 @@ fi
3453
# Remove old Go binaries
3554
if command -v go &>/dev/null; then
3655
echo "Removing existing Go binaries..."
37-
rm -f $(which go) $(which gofmt)
56+
rm -f "$(command -v go)" "$(command -v gofmt)"
3857
fi
3958

4059
# Download and install Go
4160
if wget --quiet --spider "$GO_URL"; then
42-
echo "Downloading Go $VERSION..."
61+
echo "⬇️ Downloading Go $VERSION for $GO_ARCH..."
4362
wget -q "$GO_URL" -O "$GO_TARBALL"
44-
echo "Extracting Go..."
63+
echo "📦 Extracting Go..."
4564
tar -C /usr/local -xvf "$GO_TARBALL"
4665
rm "$GO_TARBALL"
4766
else
48-
echo "Error: Go version $VERSION not found at $GO_URL" >&2
67+
echo "Error: Go version $VERSION not found at $GO_URL" >&2
4968
exit 1
5069
fi
5170

52-
# Ensure symbolic links are created
71+
# Create symlinks
5372
ln -sf /usr/local/go/bin/go /usr/local/bin/go
5473
ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt
5574

56-
# Configure GOPATH
57-
GOPATH="/opt/go"
58-
mkdir -p "$GOPATH/bin" "$GOPATH/pkg"
59-
chown -R root:sudo "$GOPATH"
60-
chmod -R 0775 "$GOPATH"
61-
62-
grep -q "^GOPATH=" /etc/environment || echo "GOPATH=$GOPATH" >> /etc/environment
63-
64-
echo "Go $VERSION installed successfully!"
75+
echo "✅ Go $VERSION installed successfully for $GO_ARCH!"
76+
echo "👉 Note: GOPATH will default to \$(go env GOPATH) (usually ~/go)."
77+
echo "👉 Add /usr/local/go/bin to your PATH if not already set."
6578
```

0 commit comments

Comments
 (0)