Go Language Development environment configuration

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

language version and IDE

System: Windows
version: go1.7
ide:sublime Text 3 + gosublime + gobuild + gocode

Go Language Environment Building

Go installation

Step description

    1. Download
    2. Installation
    3. Configuring Environment variables
    4. Inspection
  • Download

    Download Address

    • https://golang.org/dl/
    • Http://www.golangtc.com/download

    Tips

    • Note System version: Select a download source labeled Windows
    • Note the number of digits: Select 32 bits (corresponding number 386) or 64 bits (corresponding number AMD64) according to the actual number of digits of your system
    • Note suffixes: Versions with the format ". msi" can be installed directly, compared to recommended.

    The version I chose is go1.7.windows-amd64.msi

  • Installation

    Run the installation directly after downloading ". msi" .
    Note the installation path, the default location is c:\go

  • Configuring Environment variables

    Process

    • Add c:\go\bin at the end of the system variable path
    • Create a new system variable Gorootand set the value to C:\Go

    Tips

    • The variable address is related to the installation location of Go, please adjust it according to the actual installation path.
    • When Go is installed, the relevant environment variable configuration has been completed automatically. Manual configuration is not required at this time.
  • Inspection

    The win key +r key to start the Run window and enter cmd to open the command line tool.
    Enter goat the prompt.
    If you see a message similar to the following, the installation is successful.

Go Project path settings

    • Setup method

      Create a new system variable Gopath, and set the value to the work item path you want to set.
      For example, it can be set to "G:\GoProj"

    • Project Composition Description

      The project path is divided into three folders:src,bin,pkg

      • SRC Storage Project source code;
      • Pkg to store the compiled files generated;
      • The bin holds the compiled executable file;
    • Inspection

      The win key +r key to start the Run window and enter cmd to open the command line tool.
      Enter the go env at the prompt
      You can see if the gopath path setting was successful.

IDE Installation and Configuration

There are many Ides that support go language development and can be selected according to your preferences.
The installation configuration process for Sublime Text 3 with gosublime,gobuild , and Gocode is described here.

Step description

    1. Download
    2. Installation of package management tools
    3. Installing the Gosublime Plugin
    4. Installing the Gobuild Plugin
    5. Installing the Gocode Plugin
    6. Set Go nonstandard library tips
  • Download

    Download Address
    -http://www.sublimetext.com/

    Tips
    -Sublime Text 2 and Sublime text 3 configuration details slightly different
    - Sublime Text 3is recommended, but the configuration of Sublime Text 2 is also mentioned below

  • Installation of package management tools

    Installation method

    • Reference http://blog.csdn.net/sysu_cm/article/details/52583731
  • Installing the Gosublime Plugin

    Steps

    • Open Sublime Text 3
    • Use the shortcut key Ctrl + SHIFT + P to open the package management tool
    • Enter Pcipin the Open input field, you will see the full control:installpackage displayed in the prompt area, enter Gosublime, and confirm the carriage return installation
  • Installing the Gobuild Plugin

    Steps

    • Open Sublime Text 3 (Make sure it is open)
    • Use the shortcut key Ctrl + SHIFT + P to open the package management tool
    • Enter Pcipin the Open input field and enter Gobuild to confirm the carriage return installation
  • Installing the Gocode Plugin
    The Gocode plugin can add the GO code hint function to sublime Text 3.

    Premise

      • You need to install a git client and skip the "Install Git method" section if it is already installed

    Installing the Git method

      1. Windowsgit Download Address: http://msysgit.github.io/
      2. Install after download, default installation path: C:\Program files\git
      3. When the installation is complete, configure the environment:
        • Add C:\Program files\git\bin after the system variable path
        • Add C:\Program files\git\mingw64\libexec\git-core after the system variable path

    Installing the Gocode plug-in method

      • The win key +r key to start the Run window and enter cmd to open the command line tool
      • Enter go get-u github.com/nsf/gocode at the prompt
      • After get (without any hint, when the prompt appears again, then get done)
      • Enter go install Github.com/nsf/gocode at the prompt
        -If there is no error message, install it successfully. Otherwise, check to see if your computer's Git client is fully installed

    Tips

      When the
      • git client installs the configuration environment variable, the setting of the value is related to the specific installation location and the version path, which is adjusted according to the actual configuration. For example, some people may have Git-core locations in D:\Program Files\git\libexec\git-core;
      • when installing the Gocode plug-in, no information output is normal. When the instruction input is submitted, the prompt will be hidden (execution phase), please be patient, and when the prompt reappears, it indicates that the instruction has been completed.
  • Set the Go nonstandard library hint
    to make sublime Text 3 support code hints for nonstandard library packages, you must set the Gopath variable into the configuration file.

    setting method

    • open settings-default, copy all contents
    • paste content to Settings -User, to avoid frequent configuration changes due to plug-in upgrade
    • at the end of Settings-user, add the following:
       " env ": [{" Goroot ": " C:\\go ", " Gopath ": " G:\\goproj " }]  

    Tips
    If you are using sublime Text 2, you need to add the following:

     " env ": {" Goroot ": " C:\\go ", " Gopath " :  "g:\\goproj" }  

Test the development environment

Next we will run a small program to verify that the above configuration process is feasible.

  1. New code file
    • Create a new file "Hello.go"under the SRC folder of the project path and edit the following:
  2. Run the program
    • Using the shortcut key ctrl+b to open the sublime command line, enter go run hello.goat the prompt to see:
  3. Compiling the build ". exe" program
    • Use the shortcut key ctrl+b to open the sublime command line, enter go build hello.goat the prompt, and see the resulting executable file under the Bin folder of the project path.
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.