39

在linux云服务器下配置GoLang环境

 5 years ago
source link: https://studygolang.com/articles/16666?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

1、下载go环境: Golang

当然你如果可以翻墙还可以去这个网址下载 https://golang.org/dl/

下载对应版本的包

AjUR3iM.png!web

2、上传下载的文件

scp /Users/zt/Desktop/go1.11.2.linux-amd64.tar.gz [email protected]:/home/hz/桌面

raQNBvY.png!web

3、给用户添加权限

(1)在root用户下运行vim /etc/sudoers

JBNfqu7.png!web

添加:对应的用户名添加权限,我的是hz

ieAVbyn.png!web

4、在服务器上解压缩

2qMBraR.png!web

成功后去用户/usr/local查看有没有对应的go文件夹

QRneQjq.png!web

5、配置go

终端下输入cd 进如当前用户主目录

vim .bashrc

RNJBbuE.png!web

在.bashrc添加对应指令

export GOROOT=/usr/local/go

export GOPATH=$HOME/GoLang

export GOBIN=$GOPATH/bin

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

eq6nuqV.png!web

你如果按照上面步骤只需要改下第二条就可以,保存退出

运行:source .bashrc

3q6JNnb.png!web

查看go版本信息:go version

nqQnyyy.png!web

6、现在就去刚刚配置的GOPATH文件夹里写go就可以了

vim main.go

package main

func main() {

println("Hello world")

}

IJBRbiB.png!web

go run main.go

bYZzyqU.png!web

至此第一个go程序编写完成。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK