使用 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
相关推荐
软件黑马王子1 小时前
C#初级教程(4)——流程控制:从基础到实践
开发语言·c#
闲猫1 小时前
go orm GORM
开发语言·后端·golang
丁卯4042 小时前
Go语言中使用viper绑定结构体和yaml文件信息时,标签的使用
服务器·后端·golang
李白同学3 小时前
【C语言】结构体内存对齐问题
c语言·开发语言
黑子哥呢?4 小时前
安装Bash completion解决tab不能补全问题
开发语言·bash
青龙小码农4 小时前
yum报错:bash: /usr/bin/yum: /usr/bin/python: 坏的解释器:没有那个文件或目录
开发语言·python·bash·liunx
大数据追光猿4 小时前
Python应用算法之贪心算法理解和实践
大数据·开发语言·人工智能·python·深度学习·算法·贪心算法
彳卸风5 小时前
Unable to parse timestamp value: “20250220135445“, expected format is
开发语言
bing_1585 小时前
简单工厂模式 (Simple Factory Pattern) 在Spring Boot 中的应用
spring boot·后端·简单工厂模式
dorabighead5 小时前
JavaScript 高级程序设计 读书笔记(第三章)
开发语言·javascript·ecmascript