MacにRust環境 をインストール、Hello world!
Setup Rust
Install Rust
公式の手順に従って、Rust入れる。
rustc
, cargo
, rustup
コマンドツールがインストールされる。(by 公式)
In the Rust development environment, all tools are installed to the ~/.cargo/bin directory, and this is where you will find the Rust toolchain, including rustc, cargo, and rustup
Iterm
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
インストール設定を聞かれる。latest stable で良いので、1を選択。
Rust の beta などを指定して、ダウンロードしたい場合は2を選択。
Iterm
default host triple: x86_64-apple-darwin
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1 # <- ここ1を入力して、Enter
...
Configure path
installが終わると、pathを設定してと言われる。
Iterm
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
パスを設定する。
bashを使っている場合は、~/.bash_profileに
~/.zshrc
source $HOME/.cargo/env
.zshrcを読み込ませるために、sourceコマンド実行。Terminal再起動でも良い。
Iterm
$ source ~/.zshrc
cargoコマンドに、パスが通っていることを確認。
Iterm
$ cargo --version
cargo 1.57.0 (b2e52d7ca 2021-10-21)
動かしてみる
main.rsを作って、HelloWorldを実装
main.rs
fn main() {
println!("Hello world!");
}
main.rs
をコンパイル。
Terminal
$ rustc main.rs
実行ファイルを実行。
Terminal
$ ls
main main.rs
生成された実行ファイルを実行。
Terminal
$ ./main
Hello world!
参考
Author And Source
この問題について(MacにRust環境 をインストール、Hello world!), 我々は、より多くの情報をここで見つけました https://zenn.dev/kenghaya/articles/55991fae9d5d41著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Collection and Share based on the CC protocol