Created
June 20, 2024 17:57
-
-
Save PushkraJ99/68afb99a77575d7f8154448e1ecf9a93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Install Golang Stable 64Bits on Linux (Debian|Ubuntu|OpenSUSE|CentOS) | |
## http://www.linuxpro.com.br/2015/06/golang-aula-1-instalacao-da-linguagem-no-linux.html | |
## Run as root (sudo su) | |
## Thank's @geosoft1 | @gwmoura | |
GO_URL="https://go.dev/dl" | |
GO_VERSION=$(curl -s 'https://go.dev/VERSION?m=text'|head -n1) | |
GO_FILE="$GO_VERSION.linux-amd64.tar.gz" | |
# Check if user has root privileges | |
if [[ $EUID -ne 0 ]]; then | |
echo "You must run the script as root or using sudo" | |
exit 1 | |
fi | |
GET_OS=$(cat /etc/os-release | head -n1 | cut -d'=' -f2 | awk '{ print tolower($1) }'| tr -d '"') | |
if [[ $GET_OS == 'debian' || $GET_OS == 'ubuntu' ]]; then | |
apt-get update && apt-get install -y git-core | |
fi | |
if [[ $GET_OS == 'opensuse' ]]; then | |
zypper in -y git-core | |
fi | |
if [[ $GET_OS == 'centos' || $GET_OS == 'amazon' ]]; then | |
yum -y install git-core | |
fi | |
cd /tmp | |
curl -LO --progress-bar ${GO_URL}/${GO_FILE} | |
tar -zxf ${GO_FILE} -C /usr/local | |
rm -f ${GO_FILE} | |
echo 'export PATH=$PATH:/usr/local/go/bin | |
export GOPATH=$HOME/go | |
export PATH=$PATH:$GOPATH/bin' >> /etc/profile | |
echo 'export PATH=$PATH:/usr/local/go/bin | |
export GOPATH=$HOME/go | |
export PATH=$PATH:$GOPATH/bin' >> ~/.zshrc | |
echo 'export PATH=$PATH:/usr/local/go/bin | |
export GOPATH=$HOME/go | |
export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc | |
### You do not need to run commands with root or sudo | |
source /etc/profile | |
source ~/.zshrc | |
source ~/.bashrc | |
## mkdir -p $HOME/go | |
## Test if Golang is working | |
go version | |
### The output is this: | |
## go version go1.7 linux/amd64 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment