以太坊环境搭建

系统版本:Ubuntu 20.04 focal

1)准备工作
安装c/c++编译环境

sudo apt install build-essential

安装git

sudo apt install git

注意:安装结果遇到 Unable to fetch some archives, maybe run apt-get update or try with --fix-missing 时,两种解决方法如下:
1)只更新apt源后重新下载

sudo apt update (--fix-missing)

2)网络屏蔽问题,进入/etc/resolv.conf,

sudo vim /etc/resolv.conf

增添

nameserver 8.8.8.8
nameserver 223.5.5.5
nameserver 223.6.6.6

该方法未验证有效

3)更换apt源
进入开源镜像网站(以阿里云为例)
查看对应系统版本的镜像配置并复制配置信息,如
在这里插入图片描述
备份sources源文件

sudo cp /etc/apt/sources.list /etc/apt/sources.bak1

修改sources(这里使用Ubuntu自带的gedit图形编辑器,也可用vim),删除所有内容并粘贴新的配置信息

sudo gedit /etc/apt/sources.list

在这里插入图片描述

sudo apt update # 更新软件源列表
sudo apt upgrade # 若安装软件的版本过低,提示更新,可选择是否更新

2)安装nodejs
简单方法:通过apt安装非最新的稳定版本

sudo apt-get install -y nodejs

安装完查看版本,确认是否安装成功

node -v 或 nodejs -v

版本为v10.19.0(truffle要求node版本最低为v8.9.4)

安装最新的稳定版本方法:
官网下载网址 https://nodejs.org/en/download/
在这里插入图片描述
确定最新稳定版本版号为16,添加源并下载

sudo apt install curl 
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

安装后node为v16.13.0,npm为v8.1.0

3)安装npm包管理器
安装最新版本的node已包含npm,不必下载

sudo apt-get install npm

查看版本确认安装成功

npm -v

版本为6.14.4

4)安装solidity编译环境
官方安装文档 https://www.osgeo.cn/solidity/installing-solidity.html

主要是两种方法
1.使用npm安装solcjs

sudo npm install -g solc

注意:该方式安装的编译器通过solcjs命令启动,如solcjs -v查看版本

2.下载Linux软件包

sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc

该方式安装得到标准solidity编译环境
详细内容请查看官方文档

5)安装truffle
官方文档 https://www.trufflesuite.com/docs/truffle/getting-started/installation

sudo npm install -g truffle

查看版本

truffle version

在这里插入图片描述
6)安装ganache-cli(testrpc)区块链测试环境

sudo npm install -g ganache-cli
ganache-cli --version

在这里插入图片描述
若apt没有换源,使用npm下载过慢,可使用临时代理,如

sudo npm install -g truffle --registry https://registry.npm.taobao.org

npm详细换源可参考 https://cloud.tencent.com/developer/article/1588050

过程疑问(更新中):
apt与apt-get 区别 https://blog.csdn.net/liudsl/article/details/79200134
truffle安装过程出现许多warn deprecated
开发组回答 https://github.com/trufflesuite/truffle/issues/4272

参考博客
https://blog.csdn.net/bupt073114/article/details/109609227
https://www.cnblogs.com/asprout/p/14736074.html
apt换国内镜像

猜你喜欢

转载自blog.csdn.net/weixin_45934479/article/details/121328121