Skip to content

Commit 171671d

Browse files
authored
saner
1 parent 741a17c commit 171671d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Linux/install_golang.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ done
3838

3939
#-------------------------------------------------------#
4040
##Install
41+
#Check if Go is already installed and remove it
42+
if command -v go >/dev/null 2>&1; then
43+
EXISTING_GO="$(command -v go)"
44+
EXISTING_GOROOT="$(go env GOROOT 2>/dev/null || echo "")"
45+
echo "[!] Found existing Go installation at: ${EXISTING_GO}"
46+
[[ -n "${EXISTING_GOROOT}" ]] && echo "[!] GOROOT: ${EXISTING_GOROOT}"
47+
48+
# Remove from common system locations
49+
for sys_path in "/usr/local/go" "/usr/go" "/opt/go"; do
50+
[[ -d "${sys_path}" ]] && { echo "[!] Removing system Go: ${sys_path}" && sudo rm -rf "${sys_path}"; }
51+
done
52+
53+
# Remove from user locations
54+
[[ -n "${EXISTING_GOROOT}" && -d "${EXISTING_GOROOT}" && "${EXISTING_GOROOT}" != "${GO_DIR}" ]] && {
55+
echo "[!] Removing existing GOROOT: ${EXISTING_GOROOT}"
56+
rm -rf "${EXISTING_GOROOT}"
57+
}
58+
fi
4159
#Clean Existing
4260
[[ -d "${GO_DIR}" ]] && rm -rf "${GO_DIR}"
4361
[[ -d "${GO_BIN_DIR}" ]] && rm -rf "${GO_BIN_DIR}"

0 commit comments

Comments
 (0)