CentOS7安装GoLang环境及BeeGo框架

一、 安装GoLang运行环境

  1. 下载golang包

    wget https://golang.google.cn/doc/install?download=go1.15.3.linux-amd64.tar.gz
  2. 解压

    sudo tar -C /usr/local -xzf go1.15.3.linux-amd64.tar.gz
  3. 配置环境

    sudo vim /etc/profile.d/go.sh

    输入

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

    按ESC => wq!退出并保存

  4. 让配置生效

    source /etc/profile.d/go.sh

 

二、 安装beego环境

  1. 配置代理环境,以下是代理地址,配置后可以提升下载速度,配置任意一个即可。

    export GOPROXY=https://mirrors.aliyun.com/goproxy/
    export GOPROXY=https://proxy.golang.org
    export GOPROXY=https://goproxy.io
    sudo vim /etc/profile.d/go.sh
    配置如下:
    export PATH=$PATH:/usr/local/go/bin
    export GOPROXY="https://goproxy.io"
    然后source /etc/profile.d/go.sh,让配置生效
  2. 下载beego包

    go get github.com/astaxie/beego
  3. 下载bee包

    go get github.com/beego/bee
  4. 配置bee目录环境

    sudo vim /etc/profile.d/go.sh
    配置如下:

    export GOROOT=/usr/local/go
    export GOPATH=/home/zhuzi/go
    export GOBIN=$GOPATH/bin
    export PATH=$PATH:$GOROOT/bin:$GOBIN

    export GO111MODULE="on"
    export GOPROXY="https://goproxy.io"

    然后source /etc/profile.d/go.sh,让配置生效
  5. 创建第一个beego项目

    进入目录/home/zhuzi/go/src
    cd /home/zhuzi/go/src

    利用bee命令创建helloworld项目
    bee new helloworld

    控制台输出以下内容

            create   /home/zhuzi/go/src/helloworld/go.mod
          create   /home/zhuzi/go/src/helloworld/
          create   /home/zhuzi/go/src/helloworld/conf/
          create   /home/zhuzi/go/src/helloworld/controllers/
          create   /home/zhuzi/go/src/helloworld/models/
          create   /home/zhuzi/go/src/helloworld/routers/
          create   /home/zhuzi/go/src/helloworld/tests/
          create   /home/zhuzi/go/src/helloworld/static/
          create   /home/zhuzi/go/src/helloworld/static/js/
          create   /home/zhuzi/go/src/helloworld/static/css/
          create   /home/zhuzi/go/src/helloworld/static/img/
          create   /home/zhuzi/go/src/helloworld/views/
          create   /home/zhuzi/go/src/helloworld/conf/app.conf
          create   /home/zhuzi/go/src/helloworld/controllers/default.go
          create   /home/zhuzi/go/src/helloworld/views/index.tpl
          create   /home/zhuzi/go/src/helloworld/routers/router.go
          create   /home/zhuzi/go/src/helloworld/tests/default_test.go
          create   /home/zhuzi/go/src/helloworld/main.go
    2020/10/21 11:44:48 SUCCESS ▶ 0003 New application successfully created!

    进入helloworld项目根目录

    cd helloworld/

    启动helloworld项目

    bee run

    控制台输出以下内容

    ______
    | ___ \
    | |_/ / ___   ___
    | ___ \ / _ \ / _ \
    | |_/ /| __/| __/
    \____/ \___| \___| v1.11.0
    2020/10/21 11:44:57 INFO     ▶ 0001 Using 'helloworld' as 'appname'
    2020/10/21 11:44:57 INFO     ▶ 0002 Initializing watcher...
    go: downloading gopkg.in/yaml.v2 v2.2.1
    go: finding module for package github.com/shiena/ansicolor
    go: downloading github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18
    go: found github.com/shiena/ansicolor in github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18
    github.com/astaxie/beego/config
    gopkg.in/yaml.v2
    github.com/shiena/ansicolor
    github.com/astaxie/beego/session
    github.com/astaxie/beego/logs
    github.com/astaxie/beego/grace
    github.com/astaxie/beego/context
    github.com/astaxie/beego/toolbox
    github.com/astaxie/beego/context/param
    github.com/astaxie/beego
    helloworld/controllers
    helloworld/routers
    helloworld
    2020/10/21 11:45:10 SUCCESS ▶ 0003 Built Successfully!
    2020/10/21 11:45:10 INFO     ▶ 0004 Restarting 'helloworld'...
    2020/10/21 11:45:10 SUCCESS ▶ 0005 './helloworld' is running...
    2020/10/21 11:45:10.538 [I] [asm_amd64.s:1374] http server Running on http://:8080

    到此为止,GoLang环境及Beego框架安装和配置完成

posted @ 2020-10-21 14:30  icyhoo  阅读(644)  评论(0编辑  收藏  举报