|
1 | | -## 安装客户端 |
| 1 | +# 安装客户端 |
2 | 2 |
|
3 | | -本节将介绍如何安装 Geth,即 Go 语言实现的以太坊客户端。这里以 Ubuntu 16.04 操作系统为例,介绍从 PPA 仓库和从源码编译这两种方式来进行安装。 |
| 3 | +本节介绍如何安装 Geth(Go 语言实现的以太坊客户端)。Geth 是以太坊最主流的执行层客户端之一。 |
4 | 4 |
|
5 | | -### 从 PPA 直接安装 |
| 5 | +*注:自 The Merge(2022 年)之后,运行完整的以太坊节点需要同时安装执行层客户端(如 Geth)和共识层客户端(如 Prysm、Lighthouse)。仅安装 Geth 无法独立同步网络。* |
6 | 6 |
|
7 | | -首先安装必要的工具包。 |
| 7 | +## 快速安装(推荐) |
8 | 8 |
|
9 | | -```sh |
10 | | -$ apt-get install software-properties-common |
11 | | -``` |
| 9 | +### macOS |
12 | 10 |
|
13 | | -之后用以下命令添加以太坊的源。 |
| 11 | +使用 Homebrew 安装: |
14 | 12 |
|
15 | | -```sh |
16 | | -$ add-apt-repository -y ppa:ethereum/ethereum |
17 | | -$ apt-get update |
| 13 | +```bash |
| 14 | +brew tap ethereum/ethereum |
| 15 | +brew install ethereum |
18 | 16 | ``` |
19 | 17 |
|
20 | | -最后安装 go-ethereum。 |
| 18 | +### Ubuntu/Debian |
21 | 19 |
|
22 | | -```sh |
23 | | -$ apt-get install ethereum |
24 | | -``` |
| 20 | +添加 PPA 源并安装: |
25 | 21 |
|
26 | | -安装成功后,则可以开始使用命令行客户端 Geth。可用 `geth --help` 查看各命令和选项,例如,用以下命令可查看 Geth 版本为 1.6.1-stable。 |
27 | | - |
28 | | -```sh |
29 | | -$ geth version |
30 | | - |
31 | | -Geth |
32 | | -Version: 1.6.1-stable |
33 | | -Git Commit: 021c3c281629baf2eae967dc2f0a7532ddfdc1fb |
34 | | -Architecture: amd64 |
35 | | -Protocol Versions: [63 62] |
36 | | -Network Id: 1 |
37 | | -Go Version: go1.8.1 |
38 | | -Operating System: linux |
39 | | -GOPATH= |
40 | | -GOROOT=/usr/lib/go-1.8 |
| 22 | +```bash |
| 23 | +sudo add-apt-repository -y ppa:ethereum/ethereum |
| 24 | +sudo apt-get update |
| 25 | +sudo apt-get install ethereum |
41 | 26 | ``` |
42 | 27 |
|
43 | | -### 从源码编译 |
| 28 | +### Windows |
44 | 29 |
|
45 | | -也可以选择从源码进行编译安装。 |
| 30 | +从 [Geth 官方下载页面](https://geth.ethereum.org/downloads/) 下载 Windows 版本安装包。 |
46 | 31 |
|
47 | | -#### 安装 Go 语言环境 |
48 | | - |
49 | | -Go 语言环境可以自行访问 [golang.org](https://golang.org) 网站下载二进制压缩包安装。注意不推荐通过包管理器安装版本,往往比较旧。 |
50 | | - |
51 | | -如下载 Go 1.8 版本,可以采用如下命令。 |
| 32 | +### 验证安装 |
52 | 33 |
|
53 | 34 | ```bash |
54 | | -$ curl -O https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz |
| 35 | +geth version |
| 36 | +# 输出示例: |
| 37 | +# Geth |
| 38 | +# Version: 1.13.x-stable |
| 39 | +# ... |
55 | 40 | ``` |
56 | 41 |
|
57 | | -下载完成后,解压目录,并移动到合适的位置(推荐为 /usr/local 下)。 |
58 | | - |
59 | | -```bash |
60 | | -$ tar -xvf go1.8.linux-amd64.tar.gz |
61 | | -$ sudo mv go /usr/local |
62 | | -``` |
| 42 | +## 从源码编译 |
63 | 43 |
|
64 | | -安装完成后记得配置 GOPATH 环境变量。 |
| 44 | +如需使用最新开发版本或进行定制,可从源码编译。 |
65 | 45 |
|
66 | | -```bash |
67 | | -$ export GOPATH=YOUR_LOCAL_GO_PATH/Go |
68 | | -$ export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin |
69 | | -``` |
| 46 | +### 1. 安装 Go 语言环境 |
70 | 47 |
|
71 | | -此时,可以通过 `go version` 命令验证安装 是否成功。 |
| 48 | +访问 [go.dev/dl](https://go.dev/dl/) 下载并安装 Go 1.21 或更高版本。 |
72 | 49 |
|
73 | 50 | ```bash |
74 | | -$ go version |
75 | | - |
76 | | -go version go1.8 linux/amd64 |
| 51 | +# 验证安装 |
| 52 | +go version |
77 | 53 | ``` |
78 | 54 |
|
79 | | -#### 下载和编译 Geth |
| 55 | +*注:现代 Go 使用 Go Modules 管理依赖,无需配置 GOPATH。* |
80 | 56 |
|
81 | | -用以下命令安装 C 的编译器。 |
| 57 | +### 2. 克隆并编译 |
82 | 58 |
|
83 | | -```sh |
84 | | -$ apt-get install -y build-essential |
| 59 | +```bash |
| 60 | +git clone https://github.com/ethereum/go-ethereum.git |
| 61 | +cd go-ethereum |
| 62 | +make geth |
85 | 63 | ``` |
86 | 64 |
|
87 | | -下载选定的 go-ethereum 源码版本,如最新的社区版本: |
| 65 | +编译完成后,可执行文件位于 `build/bin/geth`。 |
88 | 66 |
|
89 | 67 | ```bash |
90 | | -$ git clone https://github.com/ethereum/go-ethereum |
| 68 | +./build/bin/geth version |
91 | 69 | ``` |
92 | 70 |
|
93 | | -编译安装 Geth。 |
| 71 | +## 运行节点 |
94 | 72 |
|
95 | | -```bash |
96 | | -$ cd go-ethereum |
97 | | -$ make geth |
98 | | -``` |
| 73 | +由于 The Merge 后需要执行层+共识层配合,推荐使用官方的 [ethereum-docker](https://github.com/eth-educators/ethstaker-guides) 或 [eth-docker](https://eth-docker.net/) 等工具来简化部署。 |
99 | 74 |
|
100 | | -安装成功后,可用 `build/bin/geth --help` 查看各命令和选项。例如,用以下命令可查看 Geth 版本为 1.6.3-unstable。 |
| 75 | +基本的 Geth 启动命令: |
101 | 76 |
|
102 | 77 | ```bash |
103 | | -$ build/bin/geth version |
104 | | -Geth |
105 | | -Version: 1.6.3-unstable |
106 | | -Git Commit: 067dc2cbf5121541aea8c6089ac42ce07582ead1 |
107 | | -Architecture: amd64 |
108 | | -Protocol Versions: [63 62] |
109 | | -Network Id: 1 |
110 | | -Go Version: go1.8 |
111 | | -Operating System: linux |
112 | | -GOPATH=/usr/local/gopath/ |
113 | | -GOROOT=/usr/local/go |
| 78 | +# 连接主网(需配合共识层客户端) |
| 79 | +geth --http --http.api eth,net,engine,admin |
| 80 | + |
| 81 | +# 连接 Sepolia 测试网 |
| 82 | +geth --sepolia --http |
114 | 83 | ``` |
115 | 84 |
|
| 85 | +更多配置和同步选项请参考 [Geth 官方文档](https://geth.ethereum.org/docs/)。 |
0 commit comments