Installing tools
Overview
When developing on ICP, there are two primary tools used: dfx
, a CLI tool used
to create, deploy, and manage canisters, and
a canister development kit (CDK) which provides an environment for writing
canister code in different programming languages while supporting ICP features.
Currently supported CDKs include:
Motoko: ICP's native programming language.
Gitpod and GitHub Codespaces
If you use GitHub Codespaces or Gitpod to deploy your project, installing these dependencies is not necessary.
Links to available Codespaces and Gitpod examples can be found in the hello world example.
Installing dfx
via dfxvm
dfx
is part of the IC SDK.
dfx
is natively supported on Linux or macOS 12.* Monterey or later.
There is no native support for dfx
on Windows. However, by installing the
Windows Subsystem for Linux (WSL 2), you can run dfx
on a Windows system as
described below.
Not all features of dfx
may be supported on WSL 2.
To install the IC SDK, install dfxvm
. dfxvm
is a command-line tool used for installing and switching between different versions of dfx
.
It enables developers to pivot between different projects that are built with different dfx
versions. Read more about dfxvm
.
You can download and install the latest version of dfxvm
by running the command below:
- Install on macOS/Linux
- Install on Windows
sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
If you are using a machine running Apple silicon (M1 or M2 CPU chips), you will need to have Rosetta installed, otherwise you will receive the error, Bad CPU type in executable (os error 86)
.
You can install Rosetta by running the command:
softwareupdate --install-rosetta
dfx
on Windows. However, you can develop ICP canisters on Windows using a Docker container or by installing the Windows Subsystem for Linux (WSL).Using Docker
Docker is a containerization software that allows you to run a localized version of another operating system, such as Linux, then run Linux-based software and applications. Containers do not have access to the files and applications outside of the container unless given explicit permission.
To use Docker, first install Docker Desktop.
Open the Docker Desktop application to start the Docker Daemon. Then, open a command line window and pull the DFINITY ICP developer environment Docker image:
docker pull ghcr.io/dfinity/icp-dev-env:latest
Then, run an instance of this Docker image with the command:
docker run --platform linux/x86_64 -dit ghcr.io/dfinity/icp-dev-env:latest
Confirm that your container is running by using the docker ps
command:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b197b1da16df ghcr.io/dfinity/icp-dev-env:latest "bash" 37 seconds ago Up 36 seconds peaceful_lumiere
Now you can navigate into your Docker container and begin running commands such as dfx
. To navigate into the canister, run the command:
docker exec -it <NAME> bash
Replace <NAME>
with the canister name shown in the docker ps
output.
If successful, your command line prompt will change such as:
root@b197b1da16df:/#
Verify that dfx
has been installed and is ready to use by running the command:
dfx --version
This should return the version of dfx
that was installed:
dfx 0.18.0
Using WSL 2
Follow Microsoft's instructions for installing the Windows Subsystem for Linux. Make sure you are running Windows 10 (version 2004 or higher) or Windows 11.
WSL 2 is supported on both Windows 10 and Windows 11, although Windows 11 is preferred as it has better support for WSL 2.
Supported WSL Versions
Theoretically, WSL 1 and WSL 2 should both allow you to run dfx
. However, it is recommended to use WSL 2. WSL Comparison explains the differences between WSL1 and WSL 2.
Check your WSL version
Run the command wsl –list –verbose (wsl -l -v)
to check the Linux distributions installed on your Windows machine. Below is an example output:
NAME STATE VERSION
* Ubuntu Running 2
To learn more about the wsl
command, check the command reference for WSL.
Upgrade from WSL 1
If you have WSL 1 installed, follow the upgrade instructions to upgrade to WSL 2. Basically you need to:
- Step 1: Install the WSL 2 Linux kernel update package.
- Step 2: Run the following command to set your Linux distributions to version 2:
wsl--set-version <distribution name> 2
Running Linux
After you have WSL installed, you can launch the Linux distributions by name.
For example, run the command:
Ubuntu.exe
to start the Ubuntu
distribution from the command line.
Installing dfx
via dfxvm
Once you have WSL installed, you can install dfxvm
by running:
sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
This will automatically install the latest version of dfx
on your WSL.
Troubleshooting
Node.js is not properly installed
WSL 2 has Node.js 10.x.x
installed by default. But the latest
dfx
requires Node.js 16.x.x
or 18.x.x
.Permission denied when running dfx start
Projects created from dfx
need to be on the Linux filesystem
instead of the Windows filesystem. Usually cd ~
or cd $HOME
in the WSL terminal will bring you to the home directory, and creating projects in t
here should work.
No internet access on WSL
If you don’t have internet access on WSL, for instance you cannot ping any
server successfully, most likely the nameserver on WSL is set to an internal WSL
proxy. You can check the /etc/resolv.conf
file to see if it’s the
case. If it’s true, please follow the below steps to set to a valid nameserver:
- Step 1: Create the
/etc/wsl.conf
file and add the below content to it, this will prevent WSL from regenerating the/etc/resolv.conf
file after restarting.
[network]
generateResolvConf = false
- Step 2: Modify the nameserver in the
/etc/resolv.conf
file to a valid one, for example the Google nameserver8.8.8.8
. - Step 3: On Windows, restart WSL to let this fix take effect.
wsl.exe --shutdown
Installing a CDK
Motoko
By default, Motoko is installed with dfx
. Alternatively, you can build it from
source following
these instructions.
Rust
By default, the Rust CDK is installed with dfx
. Alternatively, you can install
it yourself by adding the following dependency in your Cargo.toml
file:
[lib]
crate-type = ["cdylib"]
[dependencies]
ic-cdk = "0.12"
# Only necessary if you want to define Candid data types
candid = "0.10"
Below is a brief example on how to use the Rust CDK:
#[ic_cdk::query]
fn hello() -> String {
"world".to_string()
}
TypeScript / JavaScript
The TypeScript and JavaScript CDK, known as Azle, is supported by dfx
. Learn more about how to install and use Azle.
Azle is currently in beta and should be used with caution.
Python
The Python CDK, known as Kybra, is supported by dfx
. Learn more about how to install and use Kybra.
Kybra is currently in beta and should be used with caution.
Solidity
Solidity smart contracts can be created using the Bitfinity EVM. To use the Bitfinity EVM, you can make calls to the Bitfinity mainnet or testnet.
Learn more about how to use the Bitfinity EVM.
Bitfinity EVM is currently in beta and should be used with caution.
C++
C++ is supported through the ICPP-pro CDK.