使用 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
相关推荐
码事漫谈10 分钟前
WorkBuddy 固然很香,但豆姐她免费呀
后端
金銀銅鐵1 小时前
带您看懂字节码指令(八):数组里有什么
java·jvm·后端
zark_chuan1 小时前
怎么让 AI 写十万行代码不腐化:我的 AGENTS.md、Pre-Push 门禁与活体 Wiki
后端
郝学胜-神的一滴2 小时前
游戏设计、原型与开发 26:四种循环
开发语言·数据结构·游戏·游戏引擎·游戏策划
Rain的Java大神之路3 小时前
Spring Boot 3 升级实战:真正吃掉工期的,是 MyBatis-Plus 坐标和 Security 6 重写
java·后端·面试
泡海椒3 小时前
Java PDF 报表开发:一页简历的两种版式风格对比与折行避坑
java·开发语言·pdf
2601_962885723 小时前
如何用 Python 计算终极振荡器(Ultimate Oscillator, UOS)?
开发语言·python
源码_空间3 小时前
基于Springboot在线考试系统(源码+文档)
java·spring boot·后端
benchmark_cc5 小时前
一次获取多只股票实时行情:QuantDash `quotes.get(symbols=[...])` 批量快照
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
geovindu5 小时前
python: PCA
开发语言·后端·python·算法