以太坊源码分析(一) - Ubuntu下编译安装go-ethereum以太坊客户端

本文主要来自go-ethereum的官方安装指南:https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu

步骤:
一、获取源码
方法1:执行 git clone https://github.com/ethereum/go-ethereum
方法2:在github上直接下载源码后解压即可

二、安装go
通过添加apt仓库ppa:gophers/archive的方式安装go,按下面步骤进行
1.adding ppa:gophers/archive to your system’s Software Sources
(详见:https://launchpad.net/~gophers/+archive/ubuntu/archive)

sudo add-apt-repository ppa:gophers/archive
sudo apt-get update

2.现在可以安装go了:

sudo apt-get install -y golang

安装完后可以查看下go版本:

y@ubuntu:~/blockchain/Ethereum/go-ethereum-1.8.13$ go version
go version go1.10.1 linux/amd64

三、Set GOPATH and PATH
For Go to work properly, you need to set the following two environment variables:

Setup a go folder

mkdir -p ~/go; echo "export GOPATH=$HOME/go" >> ~/.bashrc

Update your path

echo "export PATH=$PATH:$HOME/go/bin:/usr/local/go/bin" >> ~/.bashrc

Read the environment variables into current session:

source ~/.bashrc

四、安装C compilers

sudo apt-get install -y build-essential

五、build the geth
进入go-ethereum的源码目录执行make geth开始编译geth

y@ubuntu:~/blockchain/Ethereum/go-ethereum-1.8.13$ make geth

六、启动节点
现在可以执行build/bin/geth启动节点了

y@ubuntu:~/blockchain/Ethereum/go-ethereum-1.8.13$ build/bin/geth
INFO [08-08|06:06:15.524] Maximum peer count                       ETH=25 LES=0 total=25
INFO [08-08|06:06:15.543] Starting peer-to-peer node               instance=Geth/v1.8.13-stable/linux-amd64/go1.10.1
INFO [08-08|06:06:15.544] Allocated cache and file handles         database=/home/y/.ethereum/geth/chaindata cache=768 handles=512

..........

七、配置环境变量
上述使用geth命令都要在geth所在的目录下进行,如果想在任何目录都可以执行geth命令,则需要将geth所在的目录添加至环境变量中:

echo "export PATH=$PATH:/home/y/blockchain/Ethereum/go-ethereum-1.8.13/build/bin" >> /etc/profile  
source /etc/profile

这样就可以在任意目录下使用geth命令了。

你可能感兴趣的:(区块链,以太坊源码分析)