Skip to content

Instantly share code, notes, and snippets.

@linuxbiekaisar
Last active April 12, 2020 21:44
Show Gist options
  • Save linuxbiekaisar/69dbb1da8afa7d39b251e520a15b57fb to your computer and use it in GitHub Desktop.
Save linuxbiekaisar/69dbb1da8afa7d39b251e520a15b57fb to your computer and use it in GitHub Desktop.
How to install Golang or Go on Ubuntu 18.04 LTS
# Youtube: https://www.youtube.com/watch?v=mL3iQx12Vuw
# !/bin/sh
# Golang Installation:
# Go to home directoy:
cd ~
# Download latest version from the this page: https://golang.org/dl/
curl -O https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
# verify the tarbal using SHA256 hash:
sha256sum go1.10.3.linux-amd64.tar.gz
# Now extract the downloaded file
tar xvf go1.10.3.linux-amd64.tar.gz
# You should now have a directory called go in your home directory. Recursively change go’s owner and group to root, and move it to /usr/local:
sudo chown -R root:root ./go
sudo mv go /usr/local
# Set Go’s root value, which tells Go where to look for its files.
sudo nano ~/.profile
# Add this line at the end of the file:
export GOPATH=$HOME/work
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
# If you chose an alternate installation location for Go, add these lines instead to the same file. This example shows the commands if Go is installed in your home directory:
export GOROOT=$HOME/go
export GOPATH=$HOME/work
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
# With the appropriate line pasted into your profile, save and close the file. Next, refresh your profile by running:
source ~/.profile
# Create a new directory for your Go workspace, which is where Go will build its files:
mkdir $HOME/work
# Create a simple “Hello World” Go file.
nano ~/work/src/github.com/user/hello/hello.go
# insert this line the filed opened in text editor
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
# Now run the file
go run hello.go
# finally enjoy golang on ubuntu.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment