Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Best Way to Install Go 1.7 on Ubuntu
Go is a free and open source programming language created by Google in 2007. It provides convenient tools to build simple, reliable, and efficient programs. This language is designed for writing server-side applications. This article explains how to install Go 1.7 on Ubuntu systems.
Installing Go Programming Language
To download the Go language binary archive file, use the following command −
$ wget https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz
The sample output should be like this −
--2016-12-29 10:49:44-- https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz Resolving storage.googleapis.com (storage.googleapis.com)... 216.58.197.48, 2404:6800:4007:807::2010 Connecting to storage.googleapis.com (storage.googleapis.com)|216.58.197.48|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 81618401 (78M) [application/x-gzip] Saving to: 'go1.7.1.linux-amd64.tar.gz' go1.7.1.linux-amd64 100%[===================>] 77.84M 5.98MB/s in 16s 2016-12-29 10:50:01 (4.78 MB/s) - 'go1.7.1.linux-amd64.tar.gz' saved [81618401/81618401]
To extract the downloaded archive file and move it to the desired location on system, use the following command −
$ sudo tar -zxvf go1.7.1.linux-amd64.tar.gz -C /usr/local/
The sample output should be like this −
go/ go/AUTHORS go/CONTRIBUTING.md go/CONTRIBUTORS go/LICENSE go/PATENTS go/README.md go/VERSION go/api/ go/api/README go/api/except.txt go/api/go1.1.txt go/api/go1.2.txt go/api/go1.3.txt go/api/go1.4.txt go/api/go1.5.txt go/api/go1.6.txt go/api/go1.7.txt go/api/go1.txt go/api/next.txt go/bin/ go/bin/go go/bin/godoc go/bin/gofmt ...
Setting Go Environment
There are two ways to set up the Go Environment. The following are the methods −
Current session − Applies only to the current working session
Permanent setup − Applies permanently across all sessions
Current Session Setup
Current session setup applies only to the current working session. To set up the Go environment temporarily, follow these steps −
To set the GOROOT environment variable, use the following command −
$ export GOROOT=/usr/local/go
To set up GOPATH for your workspace location, use the following command −
$ export GOPATH=$HOME/tutorialspoint/sample
To set the PATH variable to access go binary system-wide, use the following command −
$ export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
Permanent Setup
Permanent setup applies to all future sessions. To set up the Go environment permanently, follow these steps −
To open the .profile file, use the following command −
$ sudo nano ~/.profile
The sample output should be like this −
# ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. # see /usr/share/doc/bash/examples/startup-files for examples. # the files are located in the bash-doc package. # the default umask is set in /etc/profile; for setting the umask # for ssh logins, install and configure the libpam-umask package. #umask 022 ...
Now add the following lines at the end of the file −
export GOROOT=/usr/local/go export GOPATH=$HOME/tutorialspoint/sample export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
Save and close the file. To refresh your profile, use the following command −
$ source ~/.profile
Verification
To verify the Go version, use the following command −
$ go version
The sample output should be like this −
go version go1.7.1 linux/amd64
To verify all configured environment variables, use the following command −
$ go env
The sample output should be like this −
GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/tutorialspoint/tutorialspoint/sample" GORACE="" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build771783301=/tmp/go-build -gno-record-gcc-switches" CXX="g++" CGO_ENABLED="1"
Conclusion
Installing Go 1.7 on Ubuntu involves downloading the binary archive, extracting it to /usr/local/, and configuring environment variables like GOROOT, GOPATH, and PATH. The setup can be temporary for the current session or permanent by modifying the .profile file.
