📚

Rust環境構築 for Mac

2023/04/10に公開

Rust について

https://www.rust-lang.org/ja

環境構築

直接インストールの場合

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

homebrewでインストールの場合

terminal
brew install rustup-init
rustup-init

rustup-init

terminal
~ % rustup-init

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
> 1 // そのままEnterでも可

...
...
...

Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source "$HOME/.cargo/env"

Pathを追加

  • そのまま追加
terminal
source "$HOME/.cargo/env"
  • zshrcに追加する場合
terminal
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Uninstall

アンインストールをする場合

terminal
rustup self uninstall

Create Project

Hello, world! の実行

terminal
cargo new hello-rust
terminal
hello-rust % cargo run
Compiling hello-rust v0.1.0 (/Users/username/oss/hello-rust)
Finished dev [unoptimized + debuginfo] target(s) in 0.55s
Running `target/debug/hello-rust`
Hello, world!

Discussion