首页 > 数据库 > 数据库开发技术 > ?Substrate 环境安装提速文档
Substrate 环境安装提速文档(Mike版,仅限Debian/Ubuntu Linux 和 Mac brew)
curl https://getsubstrate.io -sSf | bash -s
if [[ "$OSTYPE" == "linux-gnu" ]]; thenif [[ `whoami` == "root" ]]; thenMAKE_ME_ROOT=elseMAKE_ME_ROOT=sudofiif [ -f /etc/redhat-release ]; thenecho "Redhat Linux detected."echo "This OS is not supported with this script at present. Sorry."echo "Please refer to https://github.com/paritytech/substrate for setup information."elif [ -f /etc/SuSE-release ]; thenecho "Suse Linux detected."echo "This OS is not supported with this script at present. Sorry."echo "Please refer to https://github.com/paritytech/substrate for setup information."elif [ -f /etc/arch-release ]; thenecho "Arch Linux detected."$MAKE_ME_ROOT pacman -Syu --needed cmake gcc openssl-1.0 pkgconf git clangexport OPENSSL_LIB_DIR="/usr/lib/openssl-1.0";export OPENSSL_INCLUDE_DIR="/usr/include/openssl-1.0"elif [ -f /etc/mandrake-release ]; thenecho "Mandrake Linux detected."echo "This OS is not supported with this script at present. Sorry."echo "Please refer to https://github.com/paritytech/substrate for setup information."elif [ -f /etc/debian_version ]; thenecho "Ubuntu/Debian Linux detected."$MAKE_ME_ROOT apt update$MAKE_ME_ROOT apt install -y cmake pkg-config libssl-dev git gcc build-essential clang libclang-develseecho "Unknown Linux distribution."echo "This OS is not supported with this script at present. Sorry."echo "Please refer to https://github.com/paritytech/substrate for setup information."fielif [[ "$OSTYPE" == "darwin"* ]]; thenecho "Mac OS (Darwin) detected."if ! which brew >/dev/null 2>&1; then/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"fibrew install openssl cmake llvmelif [[ "$OSTYPE" == "freebsd"* ]]; thenecho "FreeBSD detected."echo "This OS is not supported with this script at present. Sorry."echo "Please refer to https://github.com/paritytech/substrate for setup information."elseecho "Unknown operating system."echo "This OS is not supported with this script at present. Sorry."echo "Please refer to https://github.com/paritytech/substrate for setup information."fiif ! which rustup >/dev/null 2>&1; thencurl https://sh.rustup.rs -sSf | sh -s -- -ysource ~/.cargo/envrustup default stableelserustup updatefifunction install_substrate {g=`mktemp -d`git clone https://github.com/paritytech/substrate $gpushd $g./scripts/init.sh./scripts/build.shcargo install --force --path . substratepopd}if [[ "$1" == "--fast" ]]; thenecho "Skipped cargo install of 'substrate' and 'subkey'"echo "You can install manually by cloning the https://github.com/paritytech/substrate repo,"echo "building the Wasm, and using cargo to install 'substrate' and 'subkey' from the repo path."elsecargo install --force --git https://github.com/paritytech/substrate subkeyinstall_substratefif=`mktemp -d`git clone https://github.com/paritytech/substrate-up $fcp -a $f/substrate-* ~/.cargo/bincp -a $f/polkadot-* ~/.cargo/binecho "Run source ~/.cargo/env now to update environment"
简单分析一下后,可以整理出一个更高效的安装步骤。
sudo apt update
sudo apt install -y cmake pkg-config libssl-dev git gcc build-essential clang libclang-dev
brew install openssl cmake llvm
curl https://sh.rustup.rs -sSf | sh -s -- -y
source ~/.cargo/env
rustup default stable
rustup update nightly
[source.crates-io]
replace-with = "rustcc"
[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"
假设我们工作目录是 ~/works/
3.1 安装 nightly 版本的 wasm32 target,执行
cd ~/works/
rustup target add wasm32-unknown-unknown --toolchain nightly
3.2 下载 wasm-gc 源码,安装
cd ~/works/
git clone https://github.com/alexcrichton/wasm-gc
cd wasm-gc
cargo +nightly build --release --target-dir=../nightly_target
cp -af ../nightly_target/release/wasm-gc ~/.cargo/bin
3.3 (这一步可选)下载 substrate 代码
git clone https://github.com/paritytech/substrate
3.4 (这一步可选)进入下载的 substrate 代码目录,编译安装 substrate 工具和 subkey 工具
cd ~/works/substrate
cargo build --release --target-dir=../target
cp -af ../target/release/substrate ~/.cargo/bin
cargo build -p subkey --release --target-dir=../target
cp -af ../target/release/subkey ~/.cargo/bin
git clone https://github.com/paritytech/substrate-up
cp -af substrate-up/substrate-* ~/.cargo/bin
cp -af substrate-up/polkadot-* ~/.cargo/bin
# Building
Install Rust:
```bash
curl https://sh.rustup.rs -sSf | sh
```
Install required tools:
```bash
./scripts/init.sh
```
Build the WebAssembly binary:
```bash
./scripts/build.sh
```
Build all native code:
```bash
cargo build
假设我们的 node 模板代码在 ~/works/ 下。代码目录为 my_substrate_node
cd ~/works/my_substrate_node/
编译 wasm 文件
./scripts/build.sh
编译 native node
cargo build --target-dir=../target
或
cargo build --release --target-dir=../target
编译出的二进制文件在 ../target/ 中。
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。