How to install Go 1.6 on Ubuntu 16.04

Introduction

Go is a modern programming language developed by Google. It is becoming more and more popular in many applications and many companies, and provides a powerful set of libraries. This tutorial will guide you to download and install Go 1.6 and build a simple Hello World application.

Preparation

This tutorial assumes that you have access to the Ubuntu 16.04 system and configured a non-root user with sudo permissions. Students who don’t have a server can buy it from here, but I personally recommend you to use the free Tencent Cloud Developer Lab for experimentation, and then buy server.

Step 1-Install Go

In this step, we will install Go on your server.

First, connect to your Ubuntu server via ssh:

ssh sammy@your_server_ip

Visit Official Go Download Page to find the URL of the current binary version of the tarball and its SHA256 hash. Make sure you are in your home directory and use curl to retrieve the tarball:

cd ~
curl -O https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz

Next, you can use sha256sum to verify the tarball:

sha256sum go1.6.linux-amd64.tar.gz
go1.6.linux-amd64.tar.gz
e40c36ae71756198478624ed1bb4ce17597b3c19d243f3f0899bb5740d56212a  go1.6.linux-amd64.tar.gz

You will get a hash like the one highlighted in the output above. Make sure it matches the one on the download page.

Next, extract the tarball with tar. The x flag tells tar to decompress, v tells it that we want detailed output (a list of extracted files), and f tells it that we will specify the file name:

tar xvf go1.6.linux-amd64.tar.gz

You should now have a directory go in your home directory. Recursively change the go owner and group to root and move it to /usr/local:

sudo chown -R root:root ./go
sudo mv go /usr/local

**Note: **Although /usr/local/go is the officially recommended location, some users may prefer or need a different path.

Step 2-Set Go Path

In this step, we will set up some paths in your environment.

First, set the root value of Go and tell Go where to find its files.

sudo nano ~/.profile

At the end of the file, add the following line:

export GOPATH=$HOME/work
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

If you choose an alternate installation location for Go, add these lines to the same file. This example shows the command to install Go in the home directory:

export GOROOT=$HOME/go
export GOPATH=$HOME/work
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Paste the appropriate lines into your configuration file, save and close the file. Next, refresh your personal information by running

source ~/.profile

Step 3-Test your installation

Now that Go is installed and the path is set for your server, you can test to make sure that Go works as expected.

Create a new directory for the Go workspace, and Go will build its files:

mkdir $HOME/work

Then, use this command to create a directory hierarchy in this folder to create test files. If you plan to use Git to submit and store Go code on GitHub, you can replace the value user with your GitHub username. If you do not plan to use GitHub to store and manage code, your folder structure may be different, such as ~/my_project.

mkdir -p work/src/github.com/user/hello

Next, you can create a simple "Hello World" Go file.

nano ~/work/src/github.com/user/hello/hello.go

In the editor, paste the following code, use the main Go package, import the formatted IO content component, and set a new function to print "Hello, World" at runtime.

package main
​
import"fmt"
​
func main(){
 fmt.Printf("hello, world\n")}

If it runs successfully, the program will print "hello, world", which will indicate that the Go program is being compiled correctly. Save and close the file, and then compile it by calling the Go command install:

go install github.com/user/hello

After compiling the file, just execute the following command to run:

hello

If the command returns "hello, world", Go has been successfully installed and is running normally. You can use the following which command to view the location of the installed compiled binary file hello:

which hello
Output/home/user/work/bin/hello

in conclusion

By downloading and installing the latest Go package and setting its path, you can now use a system for Go development.

To learn more about installing Go 1.6 related tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.


Reference: "How to Install Go 1.6 on Ubuntu 16.04"

Recommended Posts

How to install Go on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Go on CentOS 8
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install MongoDB on Ubuntu 16.04
How to install PrestaShop on Ubuntu 16.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to install Nginx on Ubuntu 16.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to install Bacula Server on Ubuntu 14.04
How to install Ubuntu 19.10 on Raspberry Pi 4
How to install Apache Kafka on Ubuntu 18.04
How to install Apache Maven on Ubuntu 20.04
How to install Apache Tomcat 8 on Ubuntu 16.04
How to install GCC compiler on Ubuntu 18.04
How to install Graylog 1.x on Ubuntu 14.04.
How to install Zabbix on Ubuntu 16.04 Server
Install Go locale on Ubuntu16
How to install Opera web browser on Ubuntu 18.04
How to install Prometheus with Docker on Ubuntu 14.04
How to install Visual Studio Code on Ubuntu 20.04
How to install Squid proxy server on Ubuntu 18.04
How to install Pycharm and Ipython on Ubuntu 16.04/18.04
How to install and configure NATS on Ubuntu 16.04
How to install and configure Gogs on Ubuntu 18.04