Golang Tutorial: (i) Introduction and installation

Source: Internet
Author: User
Tags install go golang tutorial
This is the first article in this Golang series.
What is Golang


Golang, also known as Go, is an open-source, compiled, static type of programming language developed by Google.


The primary purpose of Golang is to make it easy to develop high-availability and highly scalable Web applications.
Why Choose Golang


Why should you choose Golang as a server-side development language instead of Python,ruby,nodejs other languages that can do the same thing?


Here are some of the benefits of choosing Go:


Go native supports concurrency (Concurrency), making it ideal for writing multithreaded programs. This is achieved through the go process (goroutine) and channels (channel), which we will discuss in a future tutorial.
Golang is a compiled language. The source code is compiled into an executable local binary (Native binary) file. This is not possible with interpreted languages such as JavaScript used in Nodejs.
The language specification is fairly simple. The entire specification has only one page, and you can even write your own Go compiler based on it:)
The Go compiler supports static linking. All the code can be linked to a "chunky" binary file, so it's easy to deploy it to a cloud server without worrying about dependency issues.


Installation


Golang supports all three platforms: Mac,windows and Linux. You can download binary files for the platform in https://golang.org/dl/.
Mac OS


Download OS X installer in https://golang.org/dl/. Double-click Run and follow the prompts to install. The Golang will be installed in the/usr/local/go directory, and the/usr/local/go/bin directory will be added to the environment variable PATH.
Windows


Download MSI installer in https://golang.org/dl/. Double-click Run and follow the prompts to install. The Golang will be installed in the C:\Go directory, and C:\Go\bin will be added to the environment variable PATH.
Linux


Method One: Install using a binary file (recommended)


1. Download binary files
wget https://storage.googleapis.com/golang/go1.7.3.linux-amd64.tar.gz


2. Unzip and create the working directory
TAR-ZXF go1.7.3.linux-amd64.tar.gz-c/usr/local/
Mkdir/golang


3. Setting Environment variables
sudo vim/etc/profile.d/go.sh
Input content
Export path= $PATH:/usr/local/go/bin
: Wq Save Exit
source/etc/profile.d/go.sh


Add Gopath Directory
Create a working directory
Mkdir-p ~/dev/go


vim/etc/profile.d/gopath.sh
Export Gopath=/miaoweiye/dev/go
: Wq Save Exit
source/etc/profile.d/gopath.sh


4. Testing
Package Main


Import "FMT"


Func Main () {
Fmt. Println ("Hello, World")
}


5. View the installation
Go version


Method Two: Install with Yum


1, first install Epel source
Yum Install Epel-y


2. Install Golang with Yum
Yum Install Go-y


3. Environment variables
Add in/etc/profile:


Export gopath=/var/www/html
Export path= $PATH: $GOPATH/bin


4. Refresh Environment variables
Source/etc/profile




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.