Installation and configuration of go development environment

Linux server configuration

Create ordinary users, add sudoers, configure $HOME/.bashrc file

The first step is to log in to the Linux system as the Root user and create a normal user.


# useradd going # 创建 going 用户,通过 going 用户登录开发机进行开发
# passwd going # 设置密码
Changing password for user going.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

The second step is to add sudoers


# sed -i '/^root.*ALL=(ALL).*ALL/a\going\tALL=(ALL) \tALL' /etc/sudoers

The third step is to replace the Yum source that comes with the CentOS 8.4 system.

Since Red Hat announced in advance that CentOS 8 will stop maintenance on December 31, 2021, the official Yum source is no longer available, so it is necessary to switch the official Yum source. Here, choose the Yum source provided by Ali.



# mv /etc/yum.repos.d /etc/yum.repos.d.bak # 先备份原有的 Yum 源
# mkdir /etc/yum.repos.d
# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# yum clean all && yum makecache

The fourth step is to log in to the Linux server with the new username (going) and password.

The fifth step is to configure the $HOME/.bashrc file.



# .bashrc
 
# User specific aliases and functions
 
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
 
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

User specific environment

Basic envs


export LANG="en_US.UTF-8" # 设置系统语言为 en_US.UTF-8,避免终端出现中文乱码
export PS1='[\u@dev \W]\$ ' # 默认的 PS1 设置会展示全部的路径,为了防止过长,这里只展示:"用户名@dev 最后的目录名"
export WORKSPACE="$HOME/workspace" # 设置工作目录
export PATH=$HOME/bin:$PATH # 将 $HOME/bin 目录加入到 PATH 变量中

Default entry folder

cd $WORKSPACE # Log in to the system, enter the workspace directory by default

Depends on installation and configuration

The first step is to install dependencies


$ sudo yum -y install make autoconf automake cmake perl-CPAN libcurl-devel libtool gcc gcc-c++ glibc-headers zlib-devel git-lfs telnet lrzsz jq expat-devel openssl-devel

The second step is to install Git.


$ cd /tmp
$ wget --no-check-certificate https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.36.1.tar.gz
$ tar -xvzf git-2.36.1.tar.gz
$ cd git-2.36.1/
$ ./configure
$ make
$ sudo make install
$ git --version          # 输出 git 版本号,说明安装成功
git version 2.36.1

tee -a $HOME/.bashrc <<'EOF'
# Configure for git
export PATH=/usr/local/libexec/git-core:$PATH
EOF

Step 3: Configure Git


$ git config --global user.name "Lingfei Kong"    # 用户名改成自己的
$ git config --global user.email "[email protected]"    # 邮箱改成自己的
$ git config --global credential.helper store    # 设置 Git,保存用户名和密码
$ git config --global core.longpaths true # 解决 Git 中 'Filename too long' 的错误

First of all, in Git, we will call non-ASCII characters Unusual characters. When Git outputs such characters to the terminal, the default is to use octal escape characters to output (to prevent garbled characters), but most terminals now support the direct display of non-ASCII characters, so we can turn off this feature, specifically The command is as follows



$ git config --global core.quotepath off

Secondly, GitHub is limited to cloning a single file of up to 100M. In order to be able to clone files larger than 100M, we also need to install Git Large File Storage. The installation method is as follows


$ git lfs install --skip-repo

Go compilation environment installation and configuration


$ wget -P /tmp/ https://golang.google.cn/dl/go1.18.3.linux-amd64.tar.gz



$ mkdir -p $HOME/go
$ tar -xvzf /tmp/go1.18.3.linux-amd64.tar.gz -C $HOME/go
$ mv $HOME/go/go $HOME/go/go1.18.3

The following environment variables are appended to the $HOME/.bashrc file



$ tee -a $HOME/.bashrc <<'EOF'
# Go envs
export GOVERSION=go1.18.3 # Go 版本设置
export GO_INSTALL_DIR=$HOME/go # Go 安装目录
export GOROOT=$GO_INSTALL_DIR/$GOVERSION # GOROOT 设置
export GOPATH=$WORKSPACE/golang # GOPATH 设置
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH # 将 Go 语言自带的和通过 go install 安装的二进制文件加入到 PATH 路径中
export GO111MODULE="on" # 开启 Go moudles 特性
export GOPROXY=https://goproxy.cn,direct # 安装 Go 模块时,代理服务器设置
export GOPRIVATE=
export GOSUMDB=off # 关闭校验 Go 依赖包的哈希值
EOF

ProtoBuf compilation environment installation

Install protoc and protoc-gen-go

Step 1: Install protobuf

$ cd /tmp/
$ git clone -b v3.21.1 --depth=1 https://github.com/protocolbuffers/protobuf
$ cd protobuf
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install
$ protoc --version # 查看 protoc 版本,成功输出版本号,说明安装成功
libprotoc 3.21.1
Step 2: Install protoc-gen-go

$ go install github.com/golang/protobuf/[email protected]

The installation and configuration of Vim IDE is divided into the following 2 steps

The first step is to install vim-go.


$ rm -f $HOME/.vim; mkdir -p ~/.vim/pack/plugins/start/
$ git clone --depth=1 https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go

Guess you like

Origin blog.csdn.net/ywtech/article/details/128552020