How to install Go & VS Code on CentOS 7

前端之家收集整理的这篇文章主要介绍了How to install Go & VS Code on CentOS 7前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Address: https://code.visualstudio.com/docs/setup/linux

[root@contoso ~]# yum install -y epel-release 
[root@contoso ~]# yum install -y dnf     ## http://man.linuxde.net/dnf
[root@contoso ~]# dnf install git       
[root@contoso ~]# dnf --version

[root@contoso ~]# yum list golang
Loaded plugins: fastestmirror,langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
golang.x86_64            1.6.3-2.el7                  base
[root@contoso ~]# 

[root@contoso ~]# wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
[root@contoso ~]# tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz
[root@contoso ~]# ls /usr/local
bin  etc  games  go  include  lib  lib64  libexec  sbin  share  src
[root@contoso ~]# 

[root@contoso ~]# cat > /etc/profile
# /etc/profile

# System wide environment and startup programs,for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment,as this
# will prevent the need for merging in future updates.

pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}


if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`/usr/bin/id -u`
        UID=`/usr/bin/id -ru`
    fi
    USER="`/usr/bin/id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
fi

HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

# By default,we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
    umask 002
else
    umask 022
fi

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then 
            . "$i"
        else
            . "$i" >/dev/null
        fi
    fi
done

unset i
unset -f pathmunge

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

export GOPATH=~/code/go
export PATH=$PATH:$GOPATH/bin
                                                    ## export PATH=$PATH:/usr/local/zend/bin
[root@contoso ~]# source /etc/profile
[root@contoso ~]# go version
go version go1.8.3 linux/amd64
[root@contoso ~]#
[root@contoso ~]# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/code/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build361399878=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
[root@contoso ~]# 

安装Visual Studio Code

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'

dnf check-update
sudo dnf install code

Or on older versions using yum:
yum check-update
sudo yum install -y code


要进入到GOPATH目录中然后执行下面的命令获取远程包
cd $GOPATH && tree -L 4
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-find-references
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/newhook/go-symbols
go get -u -v golang.org/x/tools/cmd/guru
go get -u -v github.com/cweill/gotests/...
go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv   ##安装调试工具插件

go get -v -u github.com/go-sql-driver/MysqL
go get -v -u github.com/astaxie/beego

就可以下载这个库到我们$GOPATH/src目录下了,这样我们就可以像导入其他包一样import了。

特别提醒,go get的本质是使用源代码控制工具下载这些库的源代码,比如git,hg等,所以在使用之前必须确保安装了这些源代码版本控制工具。
[root@contoso ~]# git clone https://github.com/lifei6671/mindoc.git $GOPATH/src/github.com/lifei6671/mindoc

go install github.com/nsf/gocode
go install github.com/rogpeppe/godef
go install github.com/golang/lint/golint
go install github.com/lukehoban/go-find-references
go install github.com/lukehoban/go-outline
go install sourcegraph.com/sqs/goreturns
go install golang.org/x/tools/cmd/gorename
go install github.com/tpng/gopkgs
go install github.com/newhook/go-symbols
go install github.com/peterh/liner github.com/derekparker/delve/cmd/dlv

[root@contoso ~]# code --user-data-dir=~/code/go   ## 启动开发工具
[root@contoso hello]# pwd
/root/code/go/src/contoso.org/hello
[root@contoso ~]# cd /root/code/go/src/contoso.org/hello
[root@contoso hello]# go run main.go   ## 临时性非全局执行程序   cd $GOPATH && go install contoso.org/hello && cd ~   ##安装程序
Hello World
[root@contoso hello]# 
								cd $GOPATH && go install contoso.org/book && cd ~ 

git config --global http.sslVerify false


[root@contoso ~]# cd $GOPATH
[root@contoso go]# tree
.
├── bin
├── pkg
└── src
    ├── contoso.org
    │ └── hello
    │     └── main.go
    ├── github.com
    │ └── spf13
    │     ├── afero
    │     ├── cast
    │     ├── cobra
    │     ├── fsync
    │     ├── hugo
    │     ├── jwalterweatherman
    │     ├── nitro
    │     ├── pflag
    │     └── viper
    ├── golang.org
    ├── gopkg.in
    ├── qiniupkg.com
    └── sourcegraph.com

20 directories,1 file
[root@contoso go]# go install contoso.org/hello    ##安装程序
[root@contoso go]# tree
.
├── bin
│ └── hello
├── pkg
└── src
    ├── contoso.org
    │ └── hello
    │     └── main.go
    ├── github.com
    │ └── spf13
    │     ├── afero
    │     ├── cast
    │     ├── cobra
    │     ├── fsync
    │     ├── hugo
    │     ├── jwalterweatherman
    │     ├── nitro
    │     ├── pflag
    │     └── viper
    ├── golang.org
    ├── gopkg.in
    ├── qiniupkg.com
    └── sourcegraph.com

20 directories,2 files
[root@contoso go]# cd ~
[root@contoso ~]# hello
Hello World
[root@contoso ~]# 





[root@contoso ~]# cd /root/code/go/src/contoso.org/hello
[root@contoso hello]# tree
.
├── debug
├── hello
└── main.go

0 directories,3 files
[root@contoso hello]# go build -race
[root@contoso hello]# ./hello
==================
WARNING: DATA RACE
Write at 0x0000005880e0 by goroutine 6:
  main.incCount()
      /root/code/go/src/contoso.org/hello/main.go:27 +0x9a

PrevIoUs read at 0x0000005880e0 by goroutine 7:
  main.incCount()
      /root/code/go/src/contoso.org/hello/main.go:24 +0x78

Goroutine 6 (running) created at:
  main.main()
      /root/code/go/src/contoso.org/hello/main.go:16 +0x5f

Goroutine 7 (running) created at:
  main.main()
      /root/code/go/src/contoso.org/hello/main.go:17 +0x77
==================
2463490
Found 1 data race(s)  // 找到一个资源竞争
[root@contoso hello]# 




[root@contoso go]# cd /root/code/go/src/contoso.org/hello
[root@contoso hello]# go test -v
=== RUN   TestAdd
--- PASS: TestAdd (0.00s)
PASS
ok      contoso.org/hello       0.002s
[root@contoso hello]# 





[root@contoso hello]# go test -v -coverprofile=c.out
=== RUN   TestTag
Android
Go
Java
C
--- PASS: TestTag (0.00s)
PASS
coverage: 100.0% of statements
ok      contoso.org/hello       0.003s
[root@contoso hello]# go tool cover -html=c.out -o=tag.html

file:///root/code/go/src/contoso.org/hello/tag.html#file0
原文链接:https://www.f2er.com/centos/374334.html

猜你在找的CentOS相关文章