How to Install Go 1.6 on Ubuntu 14.04

Source: Internet
Author: User
Tags install go
This is a creation in Article, where the information may have evolved or changed.

How to Install Go 1.6 on Ubuntu 14.04

Introduction

Go is a modern programming language developed by Google, uses high-level syntax similar to scripting language S. It is popular for many applications and at many companies, and have a robust set of tools and over 90,000 repos. This tutorial would walk you through downloading and installing Go 1.6, as well as building a simple Hello world applicatio N.

Prerequisites

    • One Ubuntu 14.04 Droplet
    • One sudo non-root user

Step 1-installing Go

In this step, we'll install Go on your server.

To begin, connect to your Ubuntu server via ssh :


 
  
  
  • Sammy@your_server_ip

Once connected, update and upgrade the Ubuntu packages on your server. This ensures is the latest security patches and fixes, as well as updated repos for your new packages.

  
  
  
  • sudo apt-get update
  • sudo apt-get-y upgrade

with that all, you can begin downloading the latest package for Go by running this command, which would PU ll down the "Go package" file, and save it to your current working directory, which you can determine by running   PWD .

  
  
  
  • sudo Curl-o https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz

next, use   tar   to unpack. This command would use the Tar tool to open and expand the downloaded file, and creates a folder using the package name, an D then moves it to   /usr/local .

  
  
  
  • sudo tar-xvf go1.6.linux-amd64.tar.gz
  • sudo mv go/usr/local

Some users prefer different locations for their Go installation, or may have mandated software locations. The Go package was now /usr/local Which also ensures Go are in your $PATH For Linux. It's possible to install Go to a alternate location but the $PATH Information'll change. The location of your pick to house your Go folder would be referenced later in this tutorial, so remember where you placed it I f the location is different than /usr/local.

Step 2-setting Go Paths

In this step, we'll set some paths that Go needs. The paths in this step is all given is relative to the location of the your Go installation in /usr/local . If you chose a new directory, or left the file in download, modify the commands to match your new location.

First, set Go ' root value, which tells go where to look for its files.


 
  
  
  • sudo nano ~/.profile

At the end of the file, add this line:

export PATH=$PATH:/usr/local/go/bin

If you chose a alternate installation location for Go, add these lines instead to the same file. This example shows the commands if Go are installed in your home directory:

export GOROOT=$HOME/goexport PATH=$PATH:$GOROOT/bin

With the appropriate line pasted to your profile, save and close the file. Next, refresh your profile by running:


 
  
  
  • SOURCE ~/.profile

Step 3-testing Your Install

Now this go is installed and the paths be set for your server, you can test to ensure that go is working as expected.

Create a new directory for your Go workspace, which is where Go would build its files.


 
  
  
  • mkdir $HOME/work

Now your can point Go to the new workspace you just created by exporting GOPATH .

  
  
  
  • export gopath= $HOME/work

then, create a directory hierarchy in the This folder through the command in order for your to create your test fi Le. You can replace the value   user   with your GitHub username if your plan to use Git to commit and the store your Go code on GITHUB. If you don't plan to use the GitHub to store and manage your code, your folder structure could be something different, like  ~/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

Inside your editor, paste in the content below, which uses the main Go packages, imports the formatted IO content Componen T, and sets a new function to print "Hello world" when run.

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

This file would show "Hello, World" if it successfully runs, which shows that Go is building files correctly. Save and close the file, then compile it invoking the Go command install .


 
  
  
  • Go install github.com/user/hello

With the file compiled, you can run it from simply referring to the file at your Go path.


 
  
  
  • sudo $GOPATH/bin/hello

If that command returns ' Hello World ', then Go is successfully installed and functional.

Conclusion

By downloading and installing the latest Go package and setting their paths, you are now having a Droplet to use for Go developmen T.

next, be sure to   learn some Go tips from our development team, and   how to Host your project using Martini. The Go development landscape is growing every day, and we hope it robust and exciting.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.