如何在Win11系统中使用ubuntu(WSL)终端编译 Rust 程序

第一步:安装 WSL

参考微软提供的官方指南

在管理员模式下打开 PowerShellWindows 命令提示符,方法是右键单击并选择"以管理员身份运行",输入 wsl --install wsl --update命令,然后重启计算机。

如遇其他问题,可参考CSDN文章解决。

第二步:安装 ubuntu22.04

从windows store 中下载安装

第三步:修改国内源

打开文件资源管理器,打开左侧的Linux文件夹,定位到 etc/apt/目录,将 sources.list 复制保存为 sources.list.bk

用记事本程序打开 sources.list,将其中内容修改为国内源,如清华源:

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse

deb http s://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse

第四步:启动 ubuntu22.04并更新

设置用户名、密码。sudo apt update && sudo apt upgrade -y 更新 ubuntu 系统。

第五步:安装所需软件包

sudo apt install cargo

第六步:使用WSL终端编译Rust程序

在win11系统下,打开 VScode,即可使用 WSL 终端编译 Rust 程序 。

相关推荐
Johny_Zhao3 小时前
OpenClaw中级到高级教程
linux·人工智能·信息安全·kubernetes·云计算·yum源·系统运维·openclaw
范特西林1 天前
一次 to_bits() 引发的 Rust 与 C++ 底层思考
rust
Sheffield1 天前
Docker的跨主机服务与其对应的优缺点
linux·网络协议·docker
Sheffield1 天前
Alpine是什么,为什么是Docker首选?
linux·docker·容器
冬奇Lab2 天前
一天一个开源项目(第42篇):OpenFang - 用 Rust 构建的 Agent 操作系统,16 层安全与 7 个自主 Hands
人工智能·rust·开源
Johny_Zhao2 天前
centos7安装部署openclaw
linux·人工智能·信息安全·云计算·yum源·系统运维·openclaw
haibindev2 天前
在 Windows+WSL2 上部署 OpenClaw AI员工的实践与踩坑
linux·wsl2·openclaw
量子位2 天前
Transformer论文作者重造龙虾,Rust搓出钢铁版,告别OpenClaw裸奔漏洞
rust·openai·ai编程
元Y亨H2 天前
华硕主机重装 Ubuntu 系统完全指南
ubuntu