使用 Rustup 管理 Rust 版本

文章目录

安装 Rustup

配置镜像源

bash 复制代码
echo 'export RUSTUP_DIST_SERVER=https://rsproxy.cn' >> ~/.bash_profile
echo 'export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup' >> ~/.bash_profile
# zsh 终端
echo 'export RUSTUP_DIST_SERVER=https://rsproxy.cn' >> ~/.zshrc
echo 'export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup' >> ~/.zshrc
  • 环境变量生效
bash 复制代码
source ~/.bash_profile
# zsh 终端
source ~/.zshrc

安装 Rustup

bash 复制代码
# 删除已有的 Rustup 安装
rustup self uninstall
# 安装 Rustup 并使用飞书镜像
curl --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh
# 升级 Rustup
rustup update
# 卸载 Rustup
rustup self uninstall

安装 Rust

bash 复制代码
# 列出已安装版本 Rust
rustup toolchain list
# 安装指定版本 Rust
rustup toolchain install 1.55.0
# 设置默认 Rust 版本
rustup default 1.55.0
# 当前 Rust 版本
rustc --version
# 卸载指定 Rust 版本
rustup toolchain uninstall 1.55.0
  • 安装完后重启终端再输入以下命令
bash 复制代码
# 验证 Rust 是否成功安装
rustc --version
# 验证 Cargo(Rust 的包管理工具)是否成功安装
cargo --version

VS Code插件

  • Rust Extension Pack
    • CodeLLDB 是 Rust 用来 Debug 的工具
    • rust-analyzer 进行代码诊断

创建项目

bash 复制代码
# 包含 Rust 项目结构
cargo new demo

代码示例

  • demo/src/main.rs
rust 复制代码
fn main() {
    println!("Hello, world!");
}
bash 复制代码
cd demo
# 编译并运行项目
cargo run
相关推荐
honder试试6 小时前
焊接自动化测试平台图像处理分析-模型训练推理
开发语言·python
^Rocky6 小时前
JavaScript性能优化实战
开发语言·javascript·性能优化
ponnylv6 小时前
深入剖析Spring Boot启动流程
java·开发语言·spring boot·spring
萧邀人7 小时前
第一课、Cocos Creator 3.8 安装与配置
开发语言
Jayden_Ruan7 小时前
C++逆向输出一个字符串(三)
开发语言·c++·算法
不吃鱼的羊7 小时前
启动文件Startup_vle.c
c语言·开发语言
cyforkk7 小时前
Spring Boot @RestController 注解详解
java·spring boot·后端
VBA63378 小时前
VBA之Word应用第四章第二节:段落集合Paragraphs对象(二)
开发语言
canonical_entropy8 小时前
可逆计算:一场软件构造的世界观革命
后端·aigc·ai编程