使用 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
相关推荐
一路往蓝-Anbo5 分钟前
【第42期】调试进阶(一):IDE中的Register与Memory窗口
c语言·开发语言·ide·stm32·单片机·嵌入式硬件
m0_7482495411 分钟前
Java 语言提供了八种基本类型【文123】
java·开发语言·python
a程序小傲20 分钟前
中国邮政Java面试被问:Netty的FastThreadLocal优化原理
java·服务器·开发语言·面试·职场和发展·github·哈希算法
淦。。。。25 分钟前
题解:P14013 [POCamp 2023] 送钱 / The Generous Traveler
开发语言·c++·经验分享·学习·其他·娱乐·新浪微博
小北方城市网27 分钟前
SpringBoot 集成 MyBatis-Plus 实战(高效 CRUD 与复杂查询):简化数据库操作
java·数据库·人工智能·spring boot·后端·安全·mybatis
橙露29 分钟前
C#在视觉检测中的优势:工业智能化转型的利器
开发语言·c#·视觉检测
醇氧30 分钟前
java.lang.NumberFormatException: For input string: ““
java·开发语言·spring
利刃大大33 分钟前
【ES6】变量与常量 && 模板字符串 && 对象 && 解构赋值 && 箭头函数 && 数组 && 扩展运算符 && Promise/Await/Async
开发语言·前端·javascript·es6
大猫会长39 分钟前
postgreSQL中,RLS的using与with check
开发语言·前端·javascript
老蒋每日coding1 小时前
Python:数字时代的“万能钥匙”
开发语言·python