@@ -3,41 +3,42 @@ title: Installation
3
3
---
4
4
5
5
This page will guide you through the steps needed to prepare a computer for Substrate development.
6
- As Substrate is built with [ the Rust programming language] ( https://www.rust-lang.org/ ) , the first
7
- thing you will need to do is prepare the development enviroment, these steps will vary based
8
- on the computer's operating system. You can utilize helpful utilities from the Rust toolchain
9
- to configure the Rust development environment.
6
+ Since Substrate is built with [ the Rust programming language] ( https://www.rust-lang.org/ ) , the first
7
+ thing you will need to do is prepare the computer for Rust development - these steps will vary based
8
+ on the computer's operating system. Once Rust is configured, you will use its toolchains to interact
9
+ with Rust projects; the commands for Rust's toolchains will be the same for all supported,
10
+ Unix-based operating systems.
10
11
11
- ### Unix-Based Operating Systems
12
+ ## Unix-Based Operating Systems
12
13
13
- Substrate development is optimized for Unix-based operating systems like macOS or Linux. The examples
14
+ Substrate development is easiest on Unix-based operating systems like macOS or Linux. The examples
14
15
in the Substrate [ Tutorials] ( ../../../../tutorials ) and [ Recipes] ( https://substrate.dev/recipes/ )
15
- use the terminal to demonstrate how to interact with Substrate from the command line.
16
+ use Unix-style terminals to demonstrate how to interact with Substrate from the command line.
16
17
17
- #### macOS
18
+ ### macOS
18
19
19
20
Open the Terminal application and execute the following commands:
20
21
21
22
``` bash
22
23
# Install Homebrew if necessary https://brew.sh/
23
24
/bin/bash -c " $( curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh) "
24
25
25
- # Make sure Homebrew is up-to-date and install some dependencies
26
+ # Make sure Homebrew is up-to-date, install openssl and cmake
26
27
brew update
27
28
brew install openssl cmake
28
29
```
29
30
30
- #### Ubuntu/Debian
31
+ ### Ubuntu/Debian
31
32
32
- Use your favorite terminal shell to execute the following commands:
33
+ Use a terminal shell to execute the following commands:
33
34
34
35
``` bash
35
36
sudo apt update
36
37
# May prompt for location information
37
38
sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl
38
39
```
39
40
40
- #### Arch Linux
41
+ ### Arch Linux
41
42
42
43
Run these commands from a terminal:
43
44
@@ -47,7 +48,7 @@ export OPENSSL_LIB_DIR="/usr/lib/openssl-1.0"
47
48
export OPENSSL_INCLUDE_DIR=" /usr/include/openssl-1.0"
48
49
```
49
50
50
- ### Windows
51
+ ## Windows
51
52
52
53
Please refer to the separate [ guide for Windows users] ( windows-users.md ) .
53
54
@@ -59,8 +60,7 @@ configure `rustup`:
59
60
``` bash
60
61
# Install
61
62
curl https://sh.rustup.rs -sSf | sh
62
- # Add the rust compiler and other tools to your PATH.
63
- # Make sure to add this to your shell startup script, too.
63
+ # Configure
64
64
source ~ /.cargo/env
65
65
```
66
66
@@ -74,119 +74,76 @@ rustup default stable
74
74
75
75
Substrate uses [ WebAssembly] ( https://webassembly.org/ ) (Wasm) to produce portable blockchain
76
76
runtimes. You will need to configure your Rust compiler to use
77
- [ ` nightly ` builds] ( https://doc.rust-lang.org/book/appendix-07-nightly-rust.html ) to allow
78
- compiled substrate compatible runtimes to Wasm.
77
+ [ ` nightly ` builds] ( https://doc.rust-lang.org/book/appendix-07-nightly-rust.html ) to allow you to
78
+ compile Substrate runtime code to the Wasm target .
79
79
80
80
#### Rust Nightly Toolchain
81
81
82
- Because the nightly toolchain is a moving target and receives daily changes the chance
83
- that some of them break the substrate build from time to time is non-negligible.
84
-
85
- Therefore it is advised to use a fixed nightly version rather than the latest one to
86
- build the runtime. You can install a specific version using this command:
82
+ Developers building with Substrate should use a specific Rust nightly version that is known to be
83
+ compatible with the version of Substrate they are using; this version will vary from project to
84
+ project and different projects may use different mechanisms to communicate this version to
85
+ developers. For instance, the Polkadot client specifies this information in its
86
+ [ release notes] ( https://github.com/paritytech/polkadot/releases ) . The Substrate Node Template uses
87
+ an
88
+ [ init script] ( https://github.com/substrate-developer-hub/substrate-node-template/blob/master/scripts/init.sh )
89
+ and
90
+ [ Makefile] ( https://github.com/substrate-developer-hub/substrate-node-template/blob/master/Makefile )
91
+ to specify the Rust nightly version and encapsulate the following steps. Use Rustup to install the
92
+ correct nightly:
87
93
88
94
``` bash
89
95
rustup install nightly-< yyyy-MM-dd>
90
96
```
91
97
92
- ---
93
- ** NOTE**
94
- Due to a regression in the rust compiler, using the newest rust nightly for compiling
95
- the runtime will result in compilation errors. Therefore, it is advised to use the
96
- following version until this issue is resolved:
97
-
98
- ``` bash
99
- rustup install nightly-2020-10-06
100
- ```
101
-
102
- ---
103
-
104
98
#### Wasm Toolchain
105
99
106
- Now, configure the choosen nightly version to work with the Wasm compilation target:
100
+ Now, configure the nightly version to work with the Wasm compilation target:
107
101
108
102
``` bash
109
103
rustup target add wasm32-unknown-unknown --toolchain nightly-< yyyy-MM-dd>
110
104
```
111
105
112
106
#### Specifying Nightly Version
113
107
114
- When a Substrate based project builds its included runtime it picks the latest
115
- installed nightly version by default. If the nightly version is incompatible
116
- you can override that decision by setting the ` WASM_BUILD_TOOLCHAIN ` environment variable
117
- when building the project by using the following command:
108
+ Use the ` WASM_BUILD_TOOLCHAIN ` environment variable to specify the Rust nightly version a Substrate
109
+ project should use for Wasm compilation:
118
110
119
111
``` bash
120
- WASM_BUILD_TOOLCHAIN=nightly-< yyyy-MM-dd> cargo build
112
+ WASM_BUILD_TOOLCHAIN=nightly-< yyyy-MM-dd> cargo build --release
121
113
```
122
114
123
- Note that this builds only the runtime with the specified toolchain . The rest of project will
124
- be compiled with your default toolchain, which is usually the latest installed stable toolchain.
115
+ Note that this only builds _ the runtime _ with the specified nightly . The rest of project will be
116
+ compiled with the default toolchain, i.e. the latest installed stable toolchain.
125
117
126
- #### Latest Nightly
118
+ #### Latest Nightly for Substrate ` master `
127
119
128
- If you want to build the runtime with the latest nightly compiler which should ** generally** be
129
- possible you can install the unspecific ` nightly ` toolchain:
120
+ Developers that are building Substrate _ itself_ should always use the latest bug-free versions of
121
+ Rust stable and nightly. This is because the Substrate codebase follows the tip of Rust nightly,
122
+ which means that changes in Substrate often depend on upstream changes in the Rust nightly compiler.
123
+ To ensure your Rust compiler is always up to date, you should run:
130
124
131
125
``` bash
132
- rustup install nightly
126
+ rustup update
127
+ rustup update nightly
133
128
rustup target add wasm32-unknown-unknown --toolchain nightly
134
129
```
135
130
136
- This toolchain is not tied to a specific version and will be updated just as the
137
- ` stable ` toolchain:
131
+ ** It may be necessary to occasionally rerun ` rustup update ` ** if a change in the upstream Substrate
132
+ codebase depends on a new feature of the Rust compiler.
138
133
139
- ``` bash
140
- rustup update
141
- ```
134
+ #### Downgrading Rust Nightly
142
135
143
- ## Tips
136
+ If your computer is configured to use the latest Rust nightly and you would like to downgrade to a
137
+ specific nightly version, follow these steps:
144
138
145
- ** It may be necessary to occasionally rerun ` rustup update ` ** if a change in the upstream Substrate
146
- codebase depends on the most recent version of the Rust compiler.
139
+ ``` sh
140
+ rustup uninstall nightly
141
+ rustup install nightly-< yyyy-MM-dd>
142
+ rustup target add wasm32-unknown-unknown --toolchain nightly-< yyyy-MM-dd>
143
+ ```
147
144
148
145
## Test Your Set-Up
149
146
150
147
The best way to ensure that you have successfully prepared a computer for Substrate development is
151
148
to follow the steps in our first tutorial,
152
149
[ Create Your First Substrate Chain] ( ../../tutorials/create-your-first-substrate-chain/ ) .
153
-
154
- ## Build with Nix shell
155
-
156
- Nix is a package manager for many different types of projects, including those based on Rust. Using Nix makes developers confident that the compilation output of their substrate-based projects is reliable and reproducible. Find more benefits on the [ Nix website] (https://nixos.org/ ).
157
-
158
- ### Steps to use Nix shell
159
-
160
- #### Install Nix
161
-
162
- Run the following command on a Unix based operating system:
163
- ``` shell
164
- sh <( curl -L https://nixos.org/nix/install) --daemon
165
- ```
166
-
167
- #### Verify that Nix was properly installed
168
-
169
- ``` shell
170
- nix-env --version
171
- ```
172
-
173
- You should see an output like: ` nix-env (Nix) 2.3.7 ` .
174
-
175
- #### How to use
176
-
177
- If you are using ` substrate ` or ` substrate-node-template ` , the ` shell.nix ` file should already be in the project's root directory.
178
-
179
- ``` shell
180
- cd substrate-node-template # or substrate
181
-
182
- nix-shell # start the nix shell environment by using dependencies in file `shell.nix`, it may take some time if this's your first time.
183
- ```
184
-
185
- #### Run cargo commands in the nix shell
186
-
187
-
188
- ``` shell
189
- cargo build --release # build the project
190
-
191
- ./target/release/node-template # run the compiled binary
192
- ```
0 commit comments