Skip to content

Instantly share code, notes, and snippets.

@vsc1t
Created July 7, 2019 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsc1t/0b1b5561e07e1949543723f87db2e227 to your computer and use it in GitHub Desktop.
Save vsc1t/0b1b5561e07e1949543723f87db2e227 to your computer and use it in GitHub Desktop.
Easiest install and configure GO on Ubuntu
#!/usr/bin/env bash
# Install GO for Ubuntu 18.04
# First argument spcify GOPATH varibale
# By default GOPATH=~/go
if [ "$1" ] ; then
GO_DIR=$1
else
GO_DIR='$HOME/go'
fi
PROFILE="$HOME/.profile"
EXPORT_GOPATH="export GOPATH=$GO_DIR"
PROFILE_GOPATH="if [ -d $GO_DIR ] ; then
$EXPORT_GOPATH
fi"
EXPORT_GOBIN='export PATH=$PATH:'"$GOPATH/bin"
PROFILE_GOBIN="
if [ -d $GO_DIR/bin ] ; then
$EXPORT_GOBIN
fi"
sudo apt-get update && \
sudo apt-get install snapd -y && \
sudo snap install --classic go && \
mkdir -p "$(eval echo $GO_DIR)"
if ! grep -oFq "$EXPORT_GOPATH" "$PROFILE" ; then
echo "$PROFILE_GOPATH" >> "$PROFILE"
fi
if ! grep -oFq "$EXPORT_GOBIN" "$PROFILE" ; then
echo "$PROFILE_GOBIN" >> "$PROFILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment