系统环境:Ubuntu 20.04
处理器:Intel® Core™ i5-5200U CPU @ 2.20GHz 2.20 GHz
内存:12.0 GB
1.从go官网下载安装包,因为系统为Ubuntu下载指定系统文件,并解压到user/local文件夹
sudo tar -C /usr/local -zxvf gox.x.x.linux-amd64.tar.gz
2.修改环境变量并应用到系统中
注意如果修改的是profile,只在当前命令端中有效,关闭后需要重新激活,因此,在这里选择使用修改~文件夹下的.bashrc文件来配置环境变量。
cd ~ #进入home目录
sudo vim .bashrc #更改.bashrc文件
在文件末未添加以下内容
export G0ROOT=/usr/1ocal/go #Go的根目录,即解压的go文件目录
export GOBIN=$GOROOT/bin #GO的bin文件,在Go文件夹的bin文件夹中
export GOPATH=$HOME/william/go #工作文件目录。可根据自己的需求设置
export PATH=$PATH:$GOBIN #添加环境变量
使得环境变量有效
sudo source .bashrc
3.测试Go环境是否正常安装
go version
测试结果
go version go1.16.2 linux/amd64
如果系统中有snap可以直接执行
sudo snap install go
安装Geth
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum #添加源
sudo apt-get update
sudo apt-get install ethereum #安装以太坊
新建文件夹,用来存放私链,并创建创世文件
mkdir ~/NewChain
sudo vim genesis.json
在创世文件中添加如下内容
{
"config": {
"chainId": 123,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"ethash": {}
},
"nonce": "0x0",
"timestamp": "0x5ddf8f3e",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0xfffffff0",
"difficulty": "0x1cccc8",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": { },
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
初始化创世区块
geth --datadir "~/.NewChain" init ./genesis.json
启动区块
geth --networkid 3 --datadir "./NewChain/" --identity "My_Ethereum" --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpcapi "admin,debug,eth,miner,net,personal,shh,txpool,web3" --port 30303 --rpccorsdomain "*" --nodiscover console 2>>geth.log
启动成功:
Welcome to the Geth JavaScript console!
instance: Geth/My_Ethereum/v1.10.1-stable-c2d2f4ed/linux-amd64/go1.16
coinbase: 0x1ce1f9519ed585c7658cf284cb4b2485dfb1fc0d
at block: 0 (Thu Nov 28 2019 17:11:26 GMT+0800 (CST))
datadir: /home/william/My_Ethereum/My_Ethereum
modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
To exit, press ctrl-d
>