Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Go 1.x.x in Ubuntu 18+
#!/bin/bash
if [ -z "$VERSION" ]; then
echo 'Please specify a version. e.g, "VERSION=1.11.2 sh install-go.sh"'
exit
fi
export GO_DOWNLOAD_URL=https://storage.googleapis.com/golang/go$VERSION.linux-amd64.tar.gz
export GOPATH=/workspace
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
sudo mkdir ${GOPATH}
sudo chown ${USER} -R ${GOPATH}
sudo apt update
sudo apt install --no-install-recommends -y \
software-properties-common ca-certificates build-essential
wget "$GO_DOWNLOAD_URL" -O golang.$VERSION.tar.gz
tar -zxvf golang.$VERSION.tar.gz
sudo mv go ${GOROOT}
echo "Installed Go v$VERSION"
go version
@ndaidong

This comment has been minimized.

Copy link
Owner Author

commented Mar 12, 2018

Example:

VERSION=1.11.2 sh install-go.sh

.bash_aliases

export GOPATH=/usr/local/lib/go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
@svarlamov

This comment has been minimized.

Copy link

commented Aug 12, 2018

I think that for most Go developers, it's more common (and IMO convenient) to put your GOPATH into your home directory, i.e., GOPATH=/home/ubuntu/gopkg

@bdbais

This comment has been minimized.

Copy link

commented Sep 25, 2018

apt: invalid flag: upgrade
Usage: apt
where apt options include:
-classpath Specify where to find user class files and annotation processor factories
-cp Specify where to find user class files and annotation processor factories
-d Specify where to place processor and javac generated class files
-s Specify where to place processor generated source files
-source Provide source compatibility with specified release
-version Version information
-help Print a synopsis of standard options; use javac -help for more options
-X Print a synopsis of nonstandard options
-J Pass directly to the runtime system
-A[key[=value]] Options to pass to annotation processors
-nocompile Do not compile source files to class files
-print Print out textual representation of specified types
-factorypath Specify where to find annotation processor factories
-factory Name of AnnotationProcessorFactory to use; bypasses default discovery process
See javac -help for information on javac options.
....
go version
go version go1.6.2 linux/386
....
changed 1.10 in 1.10.1 on install script and apt-get .

@ndaidong

This comment has been minimized.

Copy link
Owner Author

commented Nov 14, 2018

I think that for most Go developers, it's more common (and IMO convenient) to put your GOPATH into your home directory, i.e., GOPATH=/home/ubuntu/gopkg

I tend to create 2 different partitions and mount as /workspace and /storage, my GOPATH is being set to /workspace in which I have all the source codes, projects, etc

@ndaidong

This comment has been minimized.

Copy link
Owner Author

commented Nov 14, 2018

apt: invalid flag: upgrade
Usage: apt
where apt options include:
-classpath Specify where to find user class files and annotation processor factories
-cp Specify where to find user class files and annotation processor factories
-d Specify where to place processor and javac generated class files
-s Specify where to place processor generated source files
-source Provide source compatibility with specified release
-version Version information
-help Print a synopsis of standard options; use javac -help for more options
-X Print a synopsis of nonstandard options
-J Pass directly to the runtime system
-A[key[=value]] Options to pass to annotation processors
-nocompile Do not compile source files to class files
-print Print out textual representation of specified types
-factorypath Specify where to find annotation processor factories
-factory Name of AnnotationProcessorFactory to use; bypasses default discovery process
See javac -help for information on javac options.
....
go version
go version go1.6.2 linux/386
....
changed 1.10 in 1.10.1 on install script and apt-get .

thank you, just fixed and change to latest version 1.11.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.