Go Lang Installation On Ubuntu

Installation :-

  • Upgrade to apply the latest security updates on Ubuntu.
sudo apt-get update
sudo apt-get -y upgrade
  • You need to download the Go binary file. You can find the list of download links as per OS and architecture from below link.
https://golang.org/dl/
  • Go to the Download location using ‘cd command’
  • Extract it into /usr/local, creating a Go tree in /usr/local/go. It required sudo access to create dir into /usr/local .
cd /home/imperishable/Downloads/   //you can use your download path
sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
  • Now, let’s set up Go language environment variables GOROOT , GOPATH , GOBIN  and PATH.
  • GOROOT is the location where the Go package is installed on your system.
  • GOPATH is the location of your work directory.
  • GOBIN is directory where go install and go get will place binaries after building main packages.
export GOROOT=/usr/local/go

export GOBIN=$HOME/Go_Projects/bin

export GOPATH=$HOME/Go_Projects

export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
  • Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as
source $HOME/.profile
  • You have successfully installed and configured Go language on your system and To check Go version:
go version

Test your installation :- 

  • Create your workspace directory, $HOME/Go_Projects. (If you'd like to use a different directory, you will need to set the GOPATH environment variable.)
mkdir $HOME/Go_Projects
  • Next, make the directory src/hello inside your workspace
mkdir -p $HOME/Go_Projects/src/hello
  • In that directory create a file named hello.go that looks like
package main

import "fmt"


func main() {

	fmt.Printf("hello, world\n")

}
  • Then build it with the go tool:
cd $HOME/Go_Projects/src/hello

go run hello.go  //it will show you the output

go build   //it will genrate the binary file
  • The command above will build an executable named hello in the directory alongside your source code. Execute it to see the greeting:
./hello
  • If you see the "hello, world" message then your Go installation is working.
  • You can run go install to install the binary into your workspace's bin directory or go clean -i to remove it.
Prasanna Ravichandran

Empowering Cloud Governance | FinOps Strategist | Multi-Cloud Architect (AWS, Azure, GCP) | DevSecOps Leader | Championing Cost Optimization | Blockchain & Quantum Enthusiast

5 年

Go Lang install on Mac OS X https://link.medium.com/kLuDmKBojZ

要查看或添加评论,请登录

Akshay Ithape的更多文章

社区洞察

其他会员也浏览了