The Rustup Default Command
The rustup default
command is used to set or query the default Rust toolchain for the current user.
Getting Help
rustup default --help
- The general syntax
rustup default [toolchain]
Usage: rustup default [toolchain]
Arguments:
[toolchain] 'none', a toolchain name, such as 'stable', 'nightly', '1.8.0', or a custom toolchain name.
For more information see `rustup help toolchain`
Options:
-h, --help Print help
Discussion:
Sets the default toolchain to the one specified. If the toolchain
is not already installed then it is installed first.
Basic Usage
- Query the Default Toolchain: Running the command without any arguments will display the current default toolchain.
- Set the Default Toolchain: You can set a specific toolchain as the default by providing the toolchain name as an argument.
Querying the Default Toolchain
- To see which toolchain is currently set as the default, you can simply run:
rustup default
This command will output the name of the default toolchain, for example, here is an output from my machine:
stable-x86_64-apple-darwin (default)
Setting the Default Toolchain
- Before you set a default toolchain, you may want to list the installed toolchains in your machine. For more details on listing installed toolchains, refer to the Custom Toolchains section.
- To set a specific Rust toolchain as the default, you can specify the toolchain name. For example, if you want to set the stable toolchain as the default, you would use:
rustup default stable
If you want to set the nightly
toolchain as the default, you would use:
rustup default nightly
Example: Setting the Default Toolchain to Stable
- Set the Default Toolchain:
rustup default stable
- Verify the Default Toolchain:
rustup default
stable-x86_64-unknown-linux-gnu (default)
Setting the Default Toolchain to Nightly
- Set the Default Toolchain:
rustup default nightly
- Verify the Default Toolchain:
rustup default
nightly-x86_64-unknown-linux-gnu (default)
Use Case: Creating Rust Application with Rust Edition 2024
On my current version of Rust installed on my machine 1.78
, using Rust edition 2024 is not allowed, thus we need to set the default toolchain to nightly
- Setting the nightly toolchain
If the toolchain is not installed, then rustup will install it first and then set it to be the default for our projects.
rustup default nightly
- Check the default now
rustup default
- Create the rust application with Rust edition 2024
cargo new test_app --edition 2024 --name test-application
- Check the application
cd test_app
cargo check
- Here is the Cargo.toml file
[package]
name = "test-application"
version = "0.1.0"
edition = "2024"
[dependencies]
- Checking the application
cargo check
This command issued an error like this:
error: failed to parse manifest at `~/test_app/Cargo.toml`
Caused by:
feature `edition2024` is required
The package requires the Cargo feature called `edition2024`, but that feature is not stabilized in this version of Cargo (1.81.0-nightly (b1feb75d0 2024-06-07)).
Consider adding `cargo-features = ["edition2024"]` to the top of Cargo.toml (above the [package] table) to tell Cargo you are opting in to use this unstable feature.
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2024 for more information about the status of this feature.
So I need to add cargo-features = ["edition2024"]
to the Cargo.toml
as suggested by the compiler
- Here is the updated file:
cargo-features = ["edition2024"]
[package]
name = "test-application"
version = "0.1.0"
edition = "2024"
[dependencies]
- Now checking the application again using
cargo check
command. - The application passed and it is working fine.
Checking test-application v0.1.0 (~/test_app)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.36s
- If you need to set the stable version for other projects, it suffices to use the next command:
rustup default stable
- Check to make sure
rustup default
- Overall, you will be familiar with commands and they will become natural to you as you work with different types of Rust applications.
The rustup default command streamlines the management of the default Rust toolchain on your system. It allows for convenient switching between different Rust versions to meet your development requirements, such as:
- stable.
- beta.
- nightly.
Setting the correct default toolchain guarantees that your development environment is configured accurately for your projects.