Configuration of Golang under Linux

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

Configuration of Golang under Linux

Before the development of Golang has been under Windows, today under the Linux test, encountered some stems, such as go can not find the sync package. It took an hour to get it all settled, to record the process.

Install Go

My system is Ubuntu, completely can be installed with Apt-get, simple and convenient, but so after the installation of the above mentioned cannot find the Sync pack problem. After uninstalling the already installed go, choose to download the installation package from the official website.
Download address Select the appropriate installation package, I chose go1.6.1.linux-amd64.tar.gz. Then create a folder in your system to put the installation package, and then use wget add download address, the installation package to download to the built folder. Then type TAR-XZF go1.6.1.linux-amd64.tar.gz to unpack the installation package into the already-built folder.

A Go folder appears after decompression, and a bin folder under go. Use the ln-s (Soft Connect command) to chain the executable files under the bin to the/usr/bin, go and gofmt. You can now view the go version directly by typing the go versions command.

Configuring the Environment

Set Goroot First: export GOROOT=你建好的文件夹地址\go . The reason for setting up Goroot is that the system looks for a standard library when compiling the project. The official website also has steps to add path, this is to facilitate the system to find the go, Godoc and gofmt three executables, but this problem has been resolved through a soft connection.

Compiling the first HelloWorld server

    • First build a project folder, set the Gopath variable to point to this folderexport GOPATH=刚建的文件夹路径

    • Create a bin,src,pkg Three folder under this folder. src folder for the third-party library files, pkg Decentralized is compiled library files (. A suffix file)

    • Set the GOBIN environment variable export GOBIN=$GOPATH\bin . (The Go Install command needs to place the executable file in the directory specified by Gobin)

    • Create a package main file you can download this source file HelloWorld use wget to download to the folder you just created

    • Type the go get command to automatically install the dependency package into the SRC folder, the Helloworld.go source code of the third-party dependency package on GitHub, the installation will not be problematic. (But make sure Git is installed)

    • Type go build to compile the project, without error, you can have an executable file with the same name as the previously built folder to execute the file. Then type the access address in the browser:你的机器的ip:8080/hello

Run

Server-side

Client
The client uses the node. js to make an HTTP GET request

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.