温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Windows WSL2安装Rust开发环境的方法步骤

发布时间:2021-10-14 09:46:07 来源:亿速云 阅读:672 作者:iii 栏目:编程语言

本篇内容主要讲解“Windows WSL2安装Rust开发环境的方法步骤”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Windows WSL2安装Rust开发环境的方法步骤”吧!

安装WSL

这里安装的是Alpine Linux,体积小,消耗资源少。

  1. 安装Apline WSL

https://www.microsoft.com/en-us/p/alpine-wsl/9p804crf0395#activetab=pivot:overviewtab

Windows WSL2安装Rust开发环境的方法步骤

  1. 安装与配置:sudo命令

# 登录root
su
# 安装sudo
apk add sudo
# 将用户名添加到wheel中,才能执行sudo
addgroup [username] wheel
# 去除sudo时,输入密码
visudo
# 找到行"# %wheel ALL=(ALL) NOPASSWD: ALL"去掉'#'号取消注释,:wq保存。
  1. 添加阿里云Apline源,加速软件安装

sudo sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
  1. 安装基础软件包

sudo apk add bash wget curl git vim tar gzip build-base

安装Rust

1. 加速Rust安装

export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

2. 安装Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

3. 配置cargo阿里云源,  加速cargo install

vim ~/.cargo/config

将下面的内容,放到上方文件中,然后 :wq

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = "rustcc"
[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"

测试Rust

  1. 检查版本:

rustc -V
# 输出:rustc 1.51.0 (2fd73fabe 2021-03-23)
cargo -V
# 输出: cargo 1.51.0 (43b129a20 2021-03-16)

2. 检查是否正常build

# 创建一个demo项目
cargo new first_demo
cd first_demo
cargo build
##  输出:   Compiling first_demo v0.1.0 (/home/xxx/workspace/vscode/demo/first_demo)
##          Finished dev [unoptimized + debuginfo] target(s) in 0.78s
cargo run
##  输出:      Finished dev [unoptimized + debuginfo] target(s) in 0.00s
##             Running `target/debug/first_demo`
##  Hello, world!

安装vscode(Visual Studio Code)

  1. windows中安装vscode:

https://code.visualstudio.com/download

Windows WSL2安装Rust开发环境的方法步骤

  1. 打开VSCode, 安装   Remote - WSL   与   Rust   两款插件.

  2. “ctrl + shift + p” 调出命令,输入wsl,选择"Remote-WSL:New Window using Distro...",再选择"Apline"即可。

Windows WSL2安装Rust开发环境的方法步骤

  1. 打开创建的"first_demo",就可以开始玩耍了。

Windows WSL2安装Rust开发环境的方法步骤

到此,相信大家对“Windows WSL2安装Rust开发环境的方法步骤”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI