文章目錄
- 一、下載go環境安裝包
- 二、安裝go環境
- 三、創建測驗test用戶撰寫程式
- 四、注釋寫法
一、下載go環境安裝包
1.go官網地址
https://golang.google.cn/dl/
2.選擇stable versions(穩定版本)

二、安裝go環境
1.將軟體包上傳到linux服務器上,這里使用的是centos7.5環境
2.開始安裝go語言環境安裝包
[root@node3 ~]# tar xf go1.15.6.linux-amd64.tar.gz -C /usr/local/
3.添加環境變數
[root@node3 ~]# vim /etc/profile
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
#生效環境變數
[root@node3 ~]# source /etc/profile
#測驗環境變數是否生效 ,顯示go版本即為生效
[root@node3 ~]# go version
go version go1.15.6 linux/amd64
三、創建測驗test用戶撰寫程式
1.使用root用戶創建測驗用戶test
[root@node3 ~]# useradd test
[root@node3 ~]# passwd test
Changing password for user test.
New password: #輸入密碼
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: #確認密碼
passwd: all authentication tokens updated successfully.
2.登陸test用戶,先查看PATH環境是否包含了go的環境變數
[test@node3 ~]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/go/bin:/home/test/.local/bin:/home/test/bin
如果沒有生效的話,在source /etc/profile
3.創建屬于test的作業空間
[test@node3 ~]$ mkdir ~/go
[test@node3 ~]$ ls
go
4.添加作業目錄的環境變數
[test@node3 ~]$ vim ~/.bash_profile
#添加到最后一行
export GOPATH=$HOME/go
[test@node3 ~]$ source .bash_profile
5.創建測驗檔案
[test@node3 ~]$ mkdir go/src
[test@node3 ~]$ cd go/src/
6.一般在src下是放專案的原始碼的,我們一般以專案名為單位創建相應的目錄
[test@node3 first_go]$ vim test.go
package main
import "fmt"
func main(){ //這個"{" 的位置不能換行
fmt.Printf("hello go!\n") //Printf中的p必須大寫
}
[test@node3 first_go]$ go build
#這里就編譯好了一個和專案目錄名稱相同的可執行檔案
[test@node3 first_go]$ ls
first_go test.go
#執行
[test@node3 first_go]$ ./first_go
hello go!
四、注釋寫法
1.當行注釋: //
2.多行注釋: /* */
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/233925.html
標籤:區塊鏈
上一篇:Error: cookieParser(“secret“) required for signed cookies
