Go Language Run Environment installation detailed tutorial _golang

Source: Internet
Author: User

Three ways to install go

Go has a variety of ways to install, you can choose what you like. Here are three of the most common ways to install:

1.Go Source Installation: This is a standard software installation method. For users who often use Unix-like systems, it is most convenient and familiar for developers to install from the source.

2.Go Standard Pack Installation: Go provides a convenient installation package, supporting Windows, Linux, Mac and other systems. This method is suitable for beginners, can download the corresponding installation package according to their own system bits, all the way next can be installed easily.

3. Third-party tool installation: There are many convenient Third-party software package tools, such as Ubuntu Apt-get, Mac homebrew and so on. This installation method is suitable for those who are familiar with the corresponding system.

Finally, if you want to install more than one version of Go in the same system, you can refer to the Third-party tool GVM, which is currently the best tool in this area, unless you know what to do with it.

Go source Installation

In the go source code, some parts are written in Plan 9 C and at&t, so if you want to install from the source, you must install the C compiler tool.

In the Mac system, as long as you install the Xcode, it already contains the corresponding compiler tool.

In Unix-like systems, tools such as GCC need to be installed. For example, the Ubuntu system can install the compilation tool by performing sudo apt-get install gcc libc6-dev in the terminal.

In the Windows system, you need to install MinGW, then install GCC via MinGW and set the appropriate environment variables.

Go uses mercurial for versioning, first you have to install mercurial before you can download it. Suppose you have installed the mercurial and executed the following code:

Suppose you are already in the Go installation directory $GO _install_dir:

Copy Code code as follows:

HG Clone-u Release Https://code.google.com/p/go
CD GO/SRC
./all.bash

Installation succeeds when the word "all TESTS passed" appears after running All.bash.

This is a UNIX-style command, which is similar to installation under Windows, except that it runs All.bat, and the compiler invoked is MinGW gcc.

Then set several environment variables

Copy Code code as follows:

Export goroot= $HOME/go
Export gobin= $GOROOT/bin
Export path= $PATH: $GOBIN

See the following picture that means you have been installed successfully

Figure 1.1 The diagram that executes the GO command after the source code is installed

If the Go usage information appears, then go has been installed successfully, and if this command does not exist, you can check your PATH environment to see if the Go installation directory is included.

Go Standard Pack installation

Go provides a one-click installation of a package for each platform, which is installed by default in the following directory:/usr/local/go (Windows system: C:\Go), of course you can change their installation location, but after the change you must set the following information in your environment variable:

Copy Code code as follows:

Export goroot= $HOME/go
Export path= $PATH: $GOROOT/bin

How can you tell if your operating system is 32-bit or 64-bit?

Our next go installation needs to determine the number of bits in the operating system, so we'll determine our own system type in this section.

Windows system users press Win+r to run cmd, enter systeminfo after the return, wait a moment, will appear some system information. In the system type line, if the "X64-based PC" is displayed, it is a 64-bit system, or 32-bit system if the "X86-based PC" is displayed.

Mac system users recommend using 64-bit directly, because the MAC OS x version supported by go already does not support a pure 32-bit processor.

Linux system users can view system information by executing command arch (i.e. uname-m) in terminal:

64-bit system display

Copy Code code as follows:

x86_64

32-bit system display
Copy Code code as follows:

I386

MAC Installation

Access to the download address, 32-bit system download go1.0.3.darwin-386.pkg,64 bit system download go1.0.3.darwin-amd64.pkg, double-click the download file, all the way to the default installation click Next, this time go has been installed in your system, the default has been added in the path of the corresponding ~/go/bin, this time open the terminal, enter go

See similar to the above source code installation successful picture description has been installed successfully

If the Go usage information appears, then go has been installed successfully, and if this command does not exist, you can check your PATH environment to see if the Go installation directory is included.

Linux Installation

Access to the download address, 32-bit system download go1.0.3.linux-386.tar.gz,64 bit system download go1.0.3.linux-amd64.tar.gz,

Suppose you want to install the Go directory for $GO _install_dir, followed by the corresponding directory path.

Unzip the tar.gz package to the installation directory: Tar zxvf go1.0.3.linux-amd64.tar.gz-c $GO _install_dir.

Set Path,export path= $PATH: $GO _install_dir/go/bin

Then execute go

Figure 1.2 Information on go display after successful installation of Linux system

If the Go usage information appears, then go has been installed successfully, and if this command does not exist, you can check your PATH environment to see if the Go installation directory is included.

Windows Installation

Visit Google Code download page, 32-bit Please select the MSI installation package containing windows-386 in the name, 64-bit please select the name containing WINDOWS-AMD64. After the download is done, do not modify the default installation directory C:\Go\, if installed to other locations will cause you can not execute your own write go code. After installation, the default is to add the bin directory C:\Go\bin\ in the Go installation directory after the environment variable Path, and add the environment variable goroot, which is C:\Go\ to the Go installation root directory.

Verify that the installation is successful

In operation, enter CMD to open the command-line tool, enter go at the prompt, and check if you can see the Usage information. Enter the CD%goroot% to see if you can enter the Go installation directory. If successful, the installation is successful.

If not, please check the above environment variable Path and goroot values. If it does not exist please uninstall and reinstall after you restart the computer and retry the steps above.

Third-party tool installation

GVM

GVM is a third-party-developed go version management tool, similar to the RVM tool in Ruby. It is quite convenient to use, installation GVM use the following command:

Copy Code code as follows:

Bash < < (curl-s Https://raw.github.com/moovweb/gvm/master/binscripts/gvm-installer)

Once the installation is complete, we can install go:
Copy Code code as follows:

GVM Install go1.1
GVM Use go1.1

You can also use the following command to omit the hassle of GVM using every time you call: GVM uses go1.1--default

After executing the above command Gopath, goroot and other environment variables will automatically set up, so you can use directly.

Apt-get

Ubuntu is currently the most used Linux desktop system, using the Apt-get command to manage the package, we can use the following command to install go, in order to facilitate later, you should install Git mercurial also:

Copy Code code as follows:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:gophers/go
sudo apt-get update
sudo apt-get install golang-stable git-core Mercurial

Homebrew

Homebrew is currently the most used management software tool under the MAC system, currently supports go, can be installed directly through the command, for later convenience, you should put Git mercurial also installed on:

Copy Code code as follows:

Brew Update && Brew upgrade
Brew Install Go
Brew Install Git
Brew Install Mercurial

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.