首页 > VPS > How to Install Go 1.9 on Ubuntu 16.04 / Debian 9 / CentOS 7 / Fedora 27
2018
02-28

How to Install Go 1.9 on Ubuntu 16.04 / Debian 9 / CentOS 7 / Fedora 27

Go Lang is an open source programming language developed by a team of Google engineers in 2007. Go language was designed to resolve the common criticisms of other languages while maintaining their positive characteristics and most widely used for writing servers these days.

Most notable projects using Go language are,

  1. Docker, a set of tools for deploying containers
  2. Juju, a service orchestration tool by canonical
  3. Dropbox moved the critical components to Go lang from python
  4. snappy, a package manager

System Requirements

Go binary packages are available for below supported operating systems. Please ensure your system meets these requirements before installing Go language.

Operating system Architectures Notes
FreeBSD 8-STABLE or later x86_64 Debian GNU/kFreeBSD not supported
Linux 2.6.23 or later with glibc x86_64, arm CentOS/RHEL 5 not supported
Mac OS X 10.7 or later x86_64 use the clang or gcc that comes with Xcode for  cgo support
Windows XP or later x86_64, 386 use MinGW gcc. No need for Cygwin or msys.

 

This guide will help you to do the installation of Go 1.9 Lang on Ubuntu 16.04Ubuntu 14.04CentOS 7, RHEL 7, and Fedora 27.

Download and Install Go Language

Before installing Go language, update your system with the latest security patches to ensure the system is not vulnerable.

Switch to the root user.

Update your system using the following command.

 

Install wget package.

 

Download the Go language binary package using the following command. Alternatively, you can visit Go Language download page to download the latest version of Go.

Extract the archive and move it to /usr/local. You can also place the Go lang binary to your custom location instead of /usr/local.

Setup Go Environment variables

Now you would need to setup two important variables for Go, GOROOT (PATH) and GOPATH. Add /usr/local/go/bin to your path variable. You can add this by running below command (temporary) or place the following command in /etc/profile or $HOME/.profile file for persistent across sessions.

If you have installed Go on custom location replace /usr/local/go/bin/ with /path/to/bin/ directory.

GOPATH is a Go environment variable for your project workspace. Let’s create a workspace directory called “work” in your home directory.

Set GOPATH variable. You can add this by running below command (temporary) or place the following command in /etc/profile or $HOME/.profile file for persistent across sessions.

Verify Go Installation

Run the below command to see the version of Go language.

Check the Go environment variables we set in previous sections.

Create your first project

Assuming that you have workspace called “work” located in the $HOME directory. I am a root user, in my case “/root/work” is my workspace. Go to your workspace.

Create a directory “src/hello” under your workspace.

Let’s create a simple program (hello) to test the Go installation.

Place the following content in the hello.go file.

Now, compile it with go command.

go command will put an executable command (hello) inside the bin directory of your workspace. Execute the executable using the following command.

You should get the following greeting text.

That’s all. You have successfully installed Go.

最后编辑:
作者:Admin
想要了解更多请加群:71808134
捐 赠如果你觉得这篇文章帮助到您,请捐赠我吧!

说点什么

avatar
  Subscribe  
提醒