Build the Go development environment under Windows/linux

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

This blog is mainly about building a go development environment under Windows, because Linux is even more convenient than Windows (really?). If you are concerned about the installation of Linux, jump directly to Linux and install go. Needless to say, go to Go's official website, download Go's version of Windows. There is a zip file to download, direct decompression is used without the option of MSI installation. Or you go directly to golang:windows and install go.

Say something nonsense. Why do I choose zip instead of MSI? Relatively speaking, I prefer green software, after extracting the basic can be used, but one drawback is that we need to register the environment variable (believe that the program ape is too easy). One of the things that Msi/exe does is unzip, and some of them are automatically adding some environment variables, or maybe writing something into the registry. Well, me likes zip.

Install go under Windows

    1. Download to a disk, such as the D:\google\golang directory;
    2. Add the path to the GO command in the environment variable path, such as D:\google\golang\golang\bin; (Note the semicolon!) This earth people know, just to be able to use the Go command in CMD directly;
    3. New Goroot variable, the value of Go folder path, such as D:\google\golang\golang, here is no semicolon;

Hello,world Test

Create a new Hello.go file with the following contents:

  1. Package Main
  2. Import "FMT"
  3. func main() {
  4. FMT. Println("Hello, World")
  5. }

In CMD to switch to the directory where the Hello.go, run the command:go run hello.go, can output hello,world Normal, usually do not have problems, swelling may be a problem? O__o "....

Hello, World Test (Chinese support test)

Create a new Hello.go file with the following contents:

  1. Package Main
  2. Import "FMT"
  3. func main() {
  4. FMT. Println("Hello, World")
  5. }

In CMD to switch to the directory where the Hello.go, run the command:go run hello.go, Windows general problems, or compile pass, or, the Chinese is garbled, one is the problem of file encoding, but the CMD code page (encoding) problem, Both should be utf-8, and is not with the BOM utf-8 (without BOM!!!).

    1. Modified Hello.go file encoding for utf-8 without BOM, the general compiler has a choice;
    2. In cmd, type chcp 65001 to change the code page to Utf-8, while on the Cmd property-----font modification to Consolas or Lucida Console, in short, not the dot matrix font is good;
After the above modification, run Go run hello.go, there should be Hello, WorldThe

The problem with code pages rarely bothers us,but Sometimes it just happens, here's the point. It is also possible to note that using goagent to flip the wall, the code to run the bat to upload the code page if the GBK (936), otherwise the upload code will fail, the experience, O__o "....

Syntax highlighting in notepad++:

Go language download In the package there are many editor syntax highlighting configuration files, such as notepad++ in the Misc/notepadplus, there is a readme, you can follow that can be, here is the repetition of the explanation:

    1. Copy the Misc/notepadplus/go.xml to the Plugins/apis of the notepad++ installation directory;
    2. Copy the contents of the Misc/notepadplus/userdefinelang.xml to the Userdefinelang.xml in the notepad++ installation directory, and if the file does not exist, copy the file directly past, However, the document must be tagged before and after the contents;
    3. In the notepad++ language----custom language, import the Userdefinelang.xml file; If the custom language menu is not open, then look in the toolbar button, after the import, the basic can use syntax highlighting;
    4. If you want to open the. go file directly with notepad++, you just need to associate the. Go in Settings-and preferences.

notepad++ Run the Go program:

Because notepad++ can execute external commands, we can set the shortcut key in notepad++ and let it run directly Go Runcommand, view the results, then exit, it is convenient.
    1. The Run menu has a running submenu that opens or opens directly F5.
    2. To edit the command, go to run the current file in cmd, and then wait for the key to be tapped, and finally exit:
      Cmd/k Go Run "$ (full_current_path)" & Pause & Exit
    3. After the command is knocked in, save as a shortcut key, such as Ctrl + Shift + G, a name Golang run, of course, here is arbitrary, but not with the defined duplicates, otherwise it may be invalid;

Installation of Go under Linux:

Maybe you have go in the GCC installed, which is possible, so you don't have to install it (though it may not be the latest version). Linux under the things, you can choose binary installation, but more often is the source code installation, me here used by the binary installation, basic or decompression on the use, is so easy! (In fact, the source code is not difficult to where, the basic is./configure + make + make install, o__o "...)

    1. Go to the official website to find binary installation files under Linux, for example, Me is go1.0.3.linux-amd64.tar.gz;
    2. In a folder, such as Me is in the App file added, unzip the file;
      TAR-ZXVF go1.0.3.linux-amd64.tar.gz
    3. Set the environment variables, note the path of your package, and me in the APP directory:
      Export goroot= $HOME/app/goexport path= $PATH: $GOROOT/bin
    4. Write a Hello.go test, basic have other problems! Multi-language support, seemingly generally will not have, if you can play Chinese, the basic is already UTF-8 le.
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.