为何rustc自动降级?如何强制使用Rust 1.73.0新版本?
解决Rust自动回退到旧版本的问题
你卸载1.60.0后安装了1.73.0,但运行rustc时自动下载并切换回旧版本,可通过以下步骤强制使用1.73.0:
步骤1:查看当前工具链状态
先执行命令确认已安装的版本和默认配置:
rustup show
该命令会列出所有已安装的Rust工具链,以及当前全局默认使用的版本。
步骤2:设置全局默认工具链为1.73.0
执行以下任一命令,将全局默认工具链指定为目标版本:
# 直接指定1.73.0版本 rustup default 1.73.0 # 或者指定稳定版(后续稳定版更新会自动同步) rustup default stable
步骤3:检查项目本地工具链配置
如果仅在特定项目中出现回退,检查项目根目录下是否存在rust-toolchain或rust-toolchain.toml文件——这类文件会强制项目使用指定版本。若文件内写了1.60.0,修改为stable或1.73.0即可。
步骤4:刷新环境变量
执行命令重新加载Cargo的环境变量,确保系统PATH指向正确的工具链路径:
source "$HOME/.cargo/env"
也可以直接重启当前终端窗口,效果一致。
步骤5:验证生效
运行以下命令确认当前使用的Rust版本:
rustc -V
正常情况下会输出rustc 1.73.0 (cc66ad468 2023-10-03)。
问题上下文日志
info: profile set to 'default' info: default host triple is aarch64-apple-darwin info: syncing channel updates for 'stable-aarch64-apple-darwin' info: latest update on 2023-10-05, rust version 1.73.0 (cc66ad468 2023-10-03) info: downloading component 'cargo' info: downloading component 'clippy' info: downloading component 'rust-docs' info: downloading component 'rust-std' info: downloading component 'rustc' 54.4 MiB / 54.4 MiB (100 %) 27.7 MiB/s in 2s ETA: 0s info: downloading component 'rustfmt' info: installing component 'cargo' info: installing component 'clippy' info: installing component 'rust-docs' 13.8 MiB / 13.8 MiB (100 %) 5.5 MiB/s in 1s ETA: 0s info: installing component 'rust-std' 24.5 MiB / 24.5 MiB (100 %) 21.1 MiB/s in 1s ETA: 0s info: installing component 'rustc' 54.4 MiB / 54.4 MiB (100 %) 23.3 MiB/s in 2s ETA: 0s info: installing component 'rustfmt' info: default toolchain set to 'stable-aarch64-apple-darwin' stable-aarch64-apple-darwin installed - rustc 1.73.0 (cc66ad468 2023-10-03) Rust is installed now. Great! To get started you may need to restart your current shell. This would reload your PATH environment variable to include Cargo's bin directory ($HOME/.cargo/bin). To configure your current shell, run: source "$HOME/.cargo/env" (base) % rustc -V info: syncing channel updates for '1.60.0-aarch64-apple-darwin' info: latest update on 2022-04-07, rust version 1.60.0 (7737e0b5c 2022-04-04) info: downloading component 'cargo' info: downloading component 'clippy' info: downloading component 'rust-docs' info: downloading component 'rust-std' info: downloading component 'rustc' info: downloading component 'rustfmt' info: installing component 'cargo' info: installing component 'clippy' info: installing component 'rust-docs' info: installing component 'rust-std' info: installing component 'rustc' info: installing component 'rustfmt' rustc 1.60.0 (7737e0b5c 2022-04-04)
内容的提问来源于stack exchange,提问作者Justin Zhang
相关产品推荐
相关产品推荐

