Skip to content
On this page

安装Rustlings

注意

如果您使用的MacOS,请确保您已安装Xcode和它的开发者工具,可以使用命令xcode-select --install进行安装。

如果您使用的Linux,请确保已安装gcc。

sh
sudo apt install gcc
sh
sudo yum -y install gcc

您需要安装Rust,可以通过访问 https://rustup.rs 获取它,同时这还会安装Rust的包/项目管理器——Cargo。

MacOS/Linux

您只需要运行:

sh
curl -L https://raw.githubusercontent.com/rust-lang/rustlings/main/install.sh | bash

如果您向把Rustlings安装到别的目录,可以使用下面的命令:

sh
curl -L https://raw.githubusercontent.com/rust-lang/rustlings/main/install.sh | bash -s mypath/

安装完Rustlings,您就可以通过rustlings命令开始了。

Nix

克隆代码仓库的最新tag,然后运行nix develop或者nix-shell

sh
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.5.1)
git clone -b 5.5.1 --depth 1 https://github.com/rust-lang/rustlings
cd rustlings
# if nix version > 2.3
nix develop
# if nix version <= 2.3
nix-shell

Windows

在PowerShell(以管理员身份运行)中,将ExecutionPolicy设置为RemoteSigned

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

然后运行:

Start-BitsTransfer -Source https://raw.githubusercontent.com/rust-lang/rustlings/main/install.ps1 -Destination $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1

安装完Rustlings之后,与MacOS/Linux相同,之后你就可以运行rustlings命令了。请记住,在PowerShell中的效果更好,其他的任何终端可能会带来这样那样的问题。

如果您受到了权限被拒绝的消息,那你可能要在防病毒软件中将你克隆rustlings代码的目录加白。

手动安装

其实也是拉取代码仓库的最新tag,然后运行cargo install --path ...:

sh
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.5.1)
git clone -b 5.5.1 --depth 1 https://github.com/rust-lang/rustlings
cd rustlings
cargo install --force --path .

如果出现安装错误,那么请确保您的工具链是最新的,如果想要更新,可以运行:

sh
rustup update

剩下的就跟上面一样了,运行rustlings命令开始。

Powered by VitePress