首页 rust MacOS 安装Rust

MacOS 安装Rust

Rust是一门系统编程语言,专注于安全,尤其是并发安全,支持函数式和命令式以及泛型等编程范式的多范式语言。

相关软件版本

  1. MacOS版本:Sonoma 14.3 (23D56)
  2. Rust版本: 1.76.0

一、官方方式安装

打开Mac 终端,执行下面命令。

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

很遗憾!


info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /Users/***/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /Users/***/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /Users/***/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /Users/***/.profile
  /Users/***/.bash_profile
  /Users/***/.zshenv

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: aarch64-apple-darwin
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>

error: could not amend shell profile: '/Users/***/.profile': could not write rcfile file: '/Users/***/.profile': Permission denied (os error 13)

更换命令参数成功


curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y --no-modify-path

info: downloading installer
info: profile set to 'default'
info: default host triple is aarch64-apple-darwin
info: syncing channel updates for 'stable-aarch64-apple-darwin'
info: latest update on 2024-02-08, rust version 1.76.0 (07dca489a 2024-02-04)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
 14.7 MiB /  14.7 MiB (100 %)   8.4 MiB/s in  1s ETA:  0s
info: downloading component 'rust-std'
 24.3 MiB /  24.3 MiB (100 %)   9.3 MiB/s in  3s ETA:  0s
info: downloading component 'rustc'
 54.7 MiB /  54.7 MiB (100 %)  10.2 MiB/s in  5s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 14.7 MiB /  14.7 MiB (100 %)   5.7 MiB/s in  1s ETA:  0s
info: installing component 'rust-std'
 24.3 MiB /  24.3 MiB (100 %)  19.8 MiB/s in  1s ETA:  0s
info: installing component 'rustc'
 54.7 MiB /  54.7 MiB (100 %)  21.7 MiB/s in  2s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-aarch64-apple-darwin'

  stable-aarch64-apple-darwin installed - rustc 1.76.0 (07dca489a 2024-02-04)


Rust is installed now. Great!

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
environment variable. This has not been done automatically.

To configure your current shell, run:
source "$HOME/.cargo/env"
重新开启终端查看安装是否成功:

rustc -V
rustc 1.76.0 (07dca489a 2024-02-04)
若出现环境变量问题,请执行以下命令:

echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

问题

一些不可抗力的原因,可能会报错。

curl: (6) Could not resolve host: sh.rustup.rs
可以考虑使用Mac brew安装

二、brew方式安装

在终端上运行以下命令:

brew install rustup-init
初始化rustup,按照提示安装即可

rustup-init
若遇到环境变量问题,参照上述。
关注本站微信公众号