linux系统安装go环境
作者:快盘下载 人气:centos 安装 go 环境 环境与软件包名称
系统环境: centos7.5 go软件包: go1.17.6.linux-amd64.tar
1. 上传软件包到系统
[root@manager~]#pwd /root [root@manager~]# [root@manager~]#ls anaconda-ks.cfg go go1.17.6.linux-amd64.tar.gz redis-6.2.6.tar.gz
2. 解压软件包到/usr/local/
[root@manager~]#tar xf go1.17.6.linux-amd64.tar.gz -C /usr/local/
3. 添加环境变量
[root@manager~]#tail -1 /etc/profile export PATH=//usr/local/go/bin/:$PATH [root@manager~]#source /etc/profile
4. 执行go version 查看是否安装成功
[root@manager~]#go version go version go1.17.6 linux/amd64
5. 执行 go env 查看go环境变量
[root@manager~]#go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/root/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/root/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.17.6" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3492336170=/tmp/go-build -gno-record-gcc-switches"
6. 筛选出GOROOT 及 GOPATH
[root@manager~]#go env |egrep -i "path|root" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOMODCACHE="/root/go/pkg/mod" GOPATH="/root/go" GOROOT="/usr/local/go"
6. 创建GOPATH所需目录
[root@manager~]#tree /root/go/ /root/go/ ├── bin ├── pkg │ └── mod └── src └── main └── main.go 5 directories, 1 file [root@manager~]#
7. 测试go 代码是否可以执行
[root@manager~]#cd /root/go/src/main/ [root@manager~/go/src/main]#ls main.go [root@manager~/go/src/main]# [root@manager~/go/src/main]#cat main.go package main import ( "fmt" "reflect" ) func main () { var names = [...]string{"qiaoning","wangtao","lixianglong"} var sp = names[:2] fmt.Println(names,reflect.TypeOf(names)) fmt.Println(sp) fmt.Println("hello golang") } /* [qiaoning wangtao lixianglong] [3]string hello golang */ [root@manager~/go/src/main]#go run main.go [qiaoning wangtao lixianglong] [3]string [qiaoning wangtao] hello golang
8. 学会的第一个go程序
package main import "fmt" func qiao(){ var username,password string fmt.Println("请输入用户名") fmt.Scanln(&username) fmt.Println("username",username) fmt.Println("请输入密码") fmt.Scanln(&password) fmt.Println("password",password) if username == "qiao" && password == "123"{ fmt.Println("登录系统成功") }else{ fmt.Println("登录系统失败") } } func main() { qiao() }
9.python写法
users = str(input('请输入用户名称:')) print('users',users) password = int(input('请输入用户密码:')) print('password',password) if users == 'qiao' and password == 123: print('登录成功') else: print('登录失败')
加载全部内容