虽然之前安装过,但是还不够熟练,这次做个记录,方便以后翻看。

 

环境:在一台全新的Ubuntu机器上安装go。

 

$ cat /proc/version
Linux version 4.15.0-1065-aws (buildd@lgw01-amd64-035) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #69-Ubuntu SMP Thu Mar 26 02:17:29 UTC 2020

 

升级go版本

  • 下载,tar.gz文件。
  • 运行以下解压命令,覆盖旧版本。就成功了。

tar xfz go1.17.2.darwin-amd64.tar.gz -C /usr/local


 

1.下载Go语言安装包

官网:下载地址

2. 获取安装包

 wget https://studygolang.com/dl/golang/go1.17.linux-amd64.tar.gz
 # 解压文件
 tar xfz go1.17.linux-amd64.tar.gz -C /usr/local

3. 配置环境变量

go语言的环境变量配置,需要两个值:

  1. GOROOT是系统上安装Go软件包的位置
  2. GOPATH是工作目录的位置
#修改~/.profile
vim ~/.profile

#添加Gopath路径 
export GOROOT=/usr/local/go 
export GOPATH=/data/go 
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH 

# 激活配置 
source ~/.profile

  

注意:尝试修改 ~/.bashrc,添加环境变量,并没有生效。

4.验证是否配置成功

$ go version
go version go1.17 linux/amd64

 


继续安装make

apt install make 

 

sudo apt-get update
sudo apt-get install build-essential

 

 

安装与删除

apt install golang-go  # 安装之后发现是1.10版本,太老,没法用

apt rmove golang-go  # 卸载

 

 

 

 

早期版本

$ go version

Command 'go' not found, but can be installed with:

snap install go # version 1.16.2, or
apt install golang-go
apt install gccgo-go

See 'snap info go' for additional versions.

 

$ snap install go
error: This revision of snap "go" was published using classic confinement and thus may perform
arbitrary system changes outside of the security sandbox that snaps are usually confined to,
which may put your system at risk.

If you understand and want to proceed repeat the command including --classic.

 

虽然1.16.2是最新的,但我安装了1.15稳定版

$ snap install go --channel=1.15/stable --classic
go (1.15/stable) 1.15.10 from Michael Hudson-Doyle (mwhudson) installed
root@ip-172-31-44-132:/data# go version
Command 'go' is available in '/snap/bin/go'
The command could not be located because '/snap/bin' is not included in the PATH environment variable.
go: command not found

 

$ cd ~

$ vi .profile

添加

export PATH=$PATH:/snap/bin

$ source .profile

$ go version

go version go1.15.10 linux/amd64

 

 

$ make GenesisHeight=1121818 install

Command 'make' not found, but can be installed with:

apt install make
apt install make-guile

 

$ apt install make

$ apt install make-guile

 

$ make GenesisHeight=1121818 install

 

$ apt install gcc

$ gcc --version

$ make GenesisHeight=1121818 install

编译成功。

 

$ okexchaind version --long
okexchaind: command not found

添加环境变量:

$ vi .profile

添加

export PATH=$PATH:/root/go/bin

$ source .profile

 

命令行成功:

name: okexchain
server_name: okexchaind
client_name: okexchaincli
version: v0.16.8.3
commit: bd2ab2abdceb46c4cbdfef5c64af92b6b2711fb4
build_tags: netgo
go: go version go1.15.10 linux/amd64

 

相关文章:

  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-12
  • 2021-04-27
  • 2021-10-07
  • 2021-08-27
  • 2021-08-31
  • 2021-08-05
相关资源
相似解决方案