Environment: ubuntu 20
go: 1.17
Preface
I have told an article before FiscoBcos uses Go to call the contract, but it only involves using go-sdk to call the HelloWorld contract. Now consider a detailed use of go-sdk series.
Download golang compressed package
The version I am using is1.17
, you can go to golang official website to download the go compressed package
Use the corresponding package according to your own Linux system, I use go1.17.13.linux-amd64.tar.gz
After downloading, use remote connection tools such as winscp or mobaxtem to transfer the compressed package to the Linux machine
My personal habit is to transfer it to /usr/local
root@192-168-19-137:/usr/local# ll
总用量 131940
drwxr-xr-x 11 root root 4096 12月 13 09:24 ./
drwxr-xr-x 15 root root 4096 12月 13 09:26 ../
drwxr-xr-x 2 root root 4096 12月 6 2021 bin/
drwxr-xr-x 2 root root 4096 8月 19 2021 etc/
drwxr-xr-x 2 root root 4096 8月 19 2021 games/
-rw-rw-r-- 1 yijiu yijiu 135056550 12月 13 09:10 go1.17.13.linux-amd64.tar.gz
drwxr-xr-x 2 root root 4096 8月 19 2021 include/
drwxr-xr-x 3 root root 4096 8月 19 2021 lib/
lrwxrwxrwx 1 root root 9 11月 27 2021 man -> share/man/
drwxr-xr-x 2 root root 4096 8月 19 2021 sbin/
drwxr-xr-x 7 root root 4096 8月 19 2021 share/
drwxr-xr-x 2 root root 4096 8月 19 2021 src/
root@192-168-19-137:/usr/local#
Then use the decompression command to decompress to the current directory
tar -zxvf go1.17.13.linux-amd64.tar.gz
Then rename it
mv go1.17.13.linux-amd64 go
root@192-168-19-137:/usr/local# ll
总用量 131940
drwxr-xr-x 11 root root 4096 12月 13 09:24 ./
drwxr-xr-x 15 root root 4096 12月 13 09:26 ../
drwxr-xr-x 2 root root 4096 12月 6 2021 bin/
drwxr-xr-x 2 root root 4096 8月 19 2021 etc/
drwxr-xr-x 2 root root 4096 8月 19 2021 games/
drwxr-xr-x 10 root root 4096 7月 30 2022 go/
-rw-rw-r-- 1 yijiu yijiu 135056550 12月 13 09:10 go1.17.13.linux-amd64.tar.gz
drwxr-xr-x 2 root root 4096 8月 19 2021 include/
drwxr-xr-x 3 root root 4096 8月 19 2021 lib/
lrwxrwxrwx 1 root root 9 11月 27 2021 man -> share/man/
drwxr-xr-x 2 root root 4096 8月 19 2021 sbin/
drwxr-xr-x 7 root root 4096 8月 19 2021 share/
drwxr-xr-x 2 root root 4096 8月 19 2021 src/
Configure environment variables
edit /etc/profile
text
vim /etc/profile
Add the go environment variable code at the end
export GOROOT=/usr/local/go # go的路径
export GOPATH=/usr/project/gowarehouse:/usr/project/goproject # go的项目路径,可以配置多个,并用 :进行分隔 ,推荐第一个项目目录作为go的第三方包存放仓库
export GOBIN=/usr/project/gowarehouse/bin
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin:$GOBIN
Press :wq
to save
Use this command to make environment variables take effect
source /etc/profile
Check if successful
go version
root@192-168-19-137:/usr/local# go version
go version go1.17.13 linux/amd64
Configure other necessary environments using go-sdk
- Create a good project path
mkdir -p /usr/project/gowarehouse
mkdir -p /usr/project/goproject
mkdir -p /usr/project/gowarehouse/src
mkdir -p /usr/project/gowarehouse/bin
mkdir -p /usr/project/gowarehouse/pkg
- Modification of go env
go env -w GO111MODULE="on" # 当modules 功能启用时,依赖包的存放位置变更为$GOPATH/pkg,允许同一个package多个版本并存,且多个项目可以共享缓存的module
go env -w GOPROXY="https://goproxy.cn,direct" # 代理地址
Usego env
command to check whether the modification is successful
test
In the/usr/project/goproject
directory
pull the go-sdk project for testing
git clone https://gitee.com/FISCO-BCOS/go-sdk.git
Enter go-sdk
cd go-sdk
and then use
go mod tidy
Whether relevant dependencies can be introduced into the project during testing
If no error is reported, it means the environment configuration is normal
Conclusion
This article is about configuring the go environment. After configuration, you can use the related functions of go-sdk.