golang hello world

安装golang

下载

wget -c https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.7.1.linux-amd64.tar.gz

vim ~/.bash_profile

export PATH=$PATH:/usr/local/go/bin

测试

go version  

设置gopath环境变量

mkdir ~/gocode
vim ~/.bash_profile

新增以下内容

export GOPATH=~/gocode
export PATH=$PATH:$GOPATH/bin

导入环境变量

source ~/.bash_profile

hello world

mkdir $GOPATH/bin 
mkdir $GOPATH/pkg 
mkdir $GOPATH/github.com/user/hello -p
cd $GOPATH/github.com/user/hello

vim hello.go

package main

import "fmt"

func main() {
        fmt.Printf("Hello, world.\n")
}

go build # 构建(可执行程序在$GOPATH/github.com/user/hello) go install # 安装(可执行程序在$GOPATH/bin) hello # 运行

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

*

code