| title |
|---|
Installation |
This guide is for reference only, please check the latest information on getting starting with Substrate here.
This page will guide you through the 2 steps needed to prepare a computer for Substrate development. Since Substrate is built with the Rust programming language, the first thing you will need to do is prepare the computer for Rust development - these steps will vary based on the computer's operating system. Once Rust is configured, you will use its toolchains to interact with Rust projects; the commands for Rust's toolchains will be the same for all supported, Unix-based operating systems.
Substrate development is easiest on Unix-based operating systems like macOS or Linux. The examples in the Substrate Docs use Unix-style terminals to demonstrate how to interact with Substrate from the command line.
Use a terminal shell to execute the following commands:
sudo apt update
# May prompt for location information
sudo apt install -y git clang curl libssl-dev llvm libudev-dev make pkg-config protobuf-compilerRun these commands from a terminal:
pacman -Syu --needed --noconfirm curl git clangRun these commands from a terminal:
sudo dnf update
sudo dnf install clang curl git openssl-develRun these commands from a terminal:
sudo zypper install clang curl git openssl-devel llvm-devel libudev-develApple M1 ARM If you have an Apple M1 ARM system on a chip, make sure that you have Apple Rosetta 2 installed through
softwareupdate --install-rosetta. This is only needed to run theprotoctool during the build. The build itself and the target binaries would remain native.
Open the Terminal application and execute the following commands:
# Install Homebrew if necessary https://brew.sh/
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# Make sure Homebrew is up-to-date, install protobuf and openssl
brew update
brew install protobuf opensslPLEASE NOTE: Native Windows development of Substrate is not very well supported! It is highly recommend to use Windows Subsystem Linux (WSL) and follow the following instructions.
This guide uses https://rustup.rs installer and the rustup tool to manage the Rust toolchain.
First install and configure rustup:
# Install
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Configure
source ~/.cargo/envConfigure the Rust toolchain to default to the latest stable version:
rustup default stable
rustup update
rustup target add wasm32v1-noneNow the best way to ensure that you have successfully prepared a computer for Substrate development is to follow the steps in our first Substrate tutorial.
Sometimes you can't get the Substrate node template to compile out of the box. Here are some tips to help you work through that.
To see what Rust toolchain you are presently using, run:
rustup showThis will show something like this (Ubuntu example) output:
Default host: x86_64-unknown-linux-gnu
rustup home: /home/user/.rustup
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
active toolchain
----------------
name: stable-x86_64-unknown-linux-gnu
active because: it's the default toolchain
installed targets:
x86_64-unknown-linux-gnu
wasm32v1-none
As you can see above, the default toolchain is stable, and the
stable-x86_64-unknown-linux-gnu toolchain as well as its wasm32v1-none target is installed.
You also see that nightly-x86_64-unknown-linux-gnu is installed, but is not used unless explicitly defined as illustrated in the specify your nightly version
section.
Substrate uses WebAssembly (Wasm) to produce portable blockchain runtimes.
Developers who are building Substrate itself should always use the latest bug-free versions of Rust stable and nightly. This is because the Substrate codebase follows the tip of Rust nightly, which means that changes in Substrate often depend on upstream changes in the Rust nightly compiler. To ensure your Rust compiler is always up to date, you should run:
rustup update
rustup update nightly
rustup target add wasm32v1-none --toolchain nightlyNOTE: It may be necessary to occasionally rerun
rustup updateif a change in the upstream Substrate codebase depends on a new feature of the Rust compiler. When you do this, both your nightly and stable toolchains will be pulled to the most recent release, and for nightly, it is generally not expected to compile WASM without error (although it very often does). Be sure to specify your nightly version if you get WASM build errors fromrustupand downgrade nightly as needed.
If you want to guarantee that your build works on your computer as you update Rust and other dependencies, you should use a specific Rust nightly version that is known to be compatible with the version of Substrate they are using; this version will vary from project to project and different projects may use different mechanisms to communicate this version to developers. For instance, the Polkadot client specifies this information in its release notes.
# Specify the specific nightly toolchain in the date below:
rustup install nightly-<yyyy-MM-dd>Now, configure the nightly version to work with the Wasm compilation target:
rustup target add wasm32v1-none --toolchain nightly-<yyyy-MM-dd>Use the WASM_BUILD_TOOLCHAIN environment variable to specify the Rust nightly version a Substrate
project should use for Wasm compilation:
WASM_BUILD_TOOLCHAIN=nightly-<yyyy-MM-dd> cargo build --profile productionNote that this only builds the runtime with the specified nightly. The rest of project will be compiled with your default toolchain, i.e. the latest installed stable toolchain.
If your computer is configured to use the latest Rust nightly and you would like to downgrade to a specific nightly version, follow these steps:
rustup uninstall nightly
rustup install nightly-<yyyy-MM-dd>
rustup target add wasm32v1-none --toolchain nightly-<yyyy-MM-dd>