Tentukan versi Go terbaru

2025-08-02 02:51:36 - admin

#!/bin/bash


# Tentukan versi Go terbaru

GO_VERSION="1.22.3"

GO_TAR="go${GO_VERSION}.linux-amd64.tar.gz"

GO_URL="https://go.dev/dl/${GO_TAR}"


# Unduh dan ekstrak Go

wget ${GO_URL}

sudo rm -rf /usr/local/go

sudo tar -C /usr/local -xzf ${GO_TAR}


# Bersihkan file arsip

rm ${GO_TAR}


# Tambahkan Go ke PATH (jika belum ada)

PROFILE_FILE="$HOME/.bashrc"

if ! grep -q "/usr/local/go/bin" "$PROFILE_FILE"; then

 echo 'export PATH=$PATH:/usr/local/go/bin' >> "$PROFILE_FILE"

fi


# Terapkan perubahan PATH

source "$PROFILE_FILE"


# Buat workspace Go

mkdir -p ~/go/{bin,pkg,src}


# Tambahkan pengaturan workspace ke environment

if ! grep -q "export GOPATH=" "$PROFILE_FILE"; then

 echo 'export GOPATH=$HOME/go' >> "$PROFILE_FILE"

 echo 'export PATH=$PATH:$GOPATH/bin' >> "$PROFILE_FILE"

fi


# Terapkan perubahan GOPATH

source "$PROFILE_FILE"


# Verifikasi instalasi

echo "✅ Go version:"

go version


echo "📁 Workspace dibuat di: ~/go"

echo "✅ Instalasi dan konfigurasi selesai!"


More Posts