Skip to main content

Fix Rust installation

When encountering issues with your Rust installation, we recommend a cleanup (uninstall) first, especially if you have multiple installations (by accident or on purpose).

Uninstall existing Rust

If you've installed Rust using your OS package manager:

# Ubuntu
sudo apt remove cargo
sudo apt remove rustc
sudo apt autoremove

If you've installed Rust using rustup:

rustup self uninstall

If you've installed Rust using brew:

brew uninstall rust
note

We never recommend installing Rust using brew, especially because it makes it non-trivial to switch between different Rust versions.

If you've installed Rust using snap:

snap remove rustup

If you've installed Rust using mxpy with a version older than v9:

rm -rf ~/multiversx-sdk/vendor-rust
note

Since mxpy v9 (November of 2023), mxpy deps install rust does not create an isolated Rust installation anymore in ~/multiversx-sdk/vendor-rust. Instead, it installs Rust globally.

If you've installed Rust using mxpy v9 or later:

rustup self uninstall

Installing Rust and sc-meta

note

sc-meta is universal smart contract management tool. Please follow this for more information.

With mxpy

On Ubuntu (or Windows with WSL), you might need to install the following dependencies of Rust and sc-meta first:

sudo apt-get install build-essential pkg-config libssl-dev

Install Rust and sc-meta using mxpy:

mxpy deps install rust --overwrite
note

In addition to Rust and sc-meta, the above command also installs twiggy and wasm-opt.

For more information, go to managing dependencies using mxpy.

Without mxpy

On Ubuntu (or Windows with WSL), you might need to install the following dependencies of Rust and sc-meta first:

sudo apt-get install build-essential pkg-config libssl-dev

Install Rust as recommended on rust-lang.org:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Then, choose Proceed with installation (default).

Once Rust is installed, open a new terminal (shell), then switch to a recent stable version and install the wasm32-unknown-unknown target:

tip

Generally speaking, you should install Rust v1.78.0 (stable channel) or later, or nightly-2024-05-22 (nightly channel) or later.

rustup update
rustup default stable
rustup target add wasm32-unknown-unknown

Afterwards, install sc-meta:

cargo install multiversx-sc-meta --locked

Optionally, you may also want to install wasm-opt and twiggy:

cargo install wasm-opt
cargo install twiggy

Without mxpy (CI / CD)

On Ubuntu (or Windows with WSL), you might need to install the following dependencies of Rust and sc-meta first:

sudo apt-get install build-essential pkg-config libssl-dev

For CI / CD, install Rust as follows:

wget -O rustup.sh https://sh.rustup.rs && \
chmod +x rustup.sh && \
./rustup.sh --verbose --default-toolchain stable --target wasm32-unknown-unknown -y

cargo install multiversx-sc-meta --locked

Handle missing dependencies

On Ubuntu (or Windows with WSL), you might need to install the following dependencies of Rust and sc-meta before installing Rust:

sudo apt-get install build-essential pkg-config libssl-dev

Also see this GitHub issue.

Check your Rust installation

You can check your Rust installation by invoking rustup show:

$ rustup show

Default host: x86_64-unknown-linux-gnu
rustup home: /home/ubuntu/.rustup

installed toolchains
--------------------

[...]
stable-x86_64-unknown-linux-gnu (default)

installed targets for active toolchain
--------------------------------------

[...]
wasm32-unknown-unknown

active toolchain
----------------

[...]
stable-x86_64-unknown-linux-gnu (default)

You can also check the status of your Rust installation using mxpy:

$ mxpy deps check rust

INFO cli.deps: Checking dependency: module = rust, tag = stable
INFO modules: which rustc: /home/ubuntu/.cargo/bin/rustc
INFO modules: which cargo: /home/ubuntu/.cargo/bin/cargo
INFO modules: which sc-meta: /home/ubuntu/.cargo/bin/sc-meta
INFO modules: which wasm-opt: /home/ubuntu/.cargo/bin/wasm-opt
INFO modules: which twiggy: /home/ubuntu/.cargo/bin/twiggy
INFO cli.deps: [rust stable] is installed.