LoginSignup
1
0

More than 1 year has passed since last update.

Mac(macOS Big Sur)にRust環境を入れてみた。

Posted at

はじめに

最近よく目にするRustを実際に試してみたいと思い、自前のMacbookPro(16-inch, 2019)へRust環境を導入、設定してみたので、記事に残しました。なお、今回はIntel Macへの導入になりますので、M1 Macでの導入を検討されている方は、参考サイトに載せたサイトをご覧いただくのが良いと思います。
Homebrewでもインストール可能みたいですが、今回はRustのサイトに載っているインストール方法をそのまま実行しています。

PC環境

今回Rust環境を導入したPC環境は以下です。

  • MacBook Pro(16-inch, 2019)
    • CPU:Intel Corei9(2.3GHz, 8core)
    • メモリ:16GB
    • OS:macOS Big Sur ver.11.3.1

Rust環境の導入

Rust環境を導入について以下に記載するが、Rustコンパイラを実行するためにはリンカが必要となるため、先にxcodeを確認する。

xcodeのバージョン確認

$ xcode-select -v
xcode-select version 2384.

$ cc -v
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin20.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

もし、Appleのコマンドライン開発ツールがインストールされていない場合は以下の以下のコマンドでインストールを実施します。

$ xcode-select --install

Rustupインストール

Rustupをインストールすることで、Cargoやrustcなど必要なツール類がインストールされます。
インストールを開始すると、rustupのインストール方法に関して選択するメッセージが表示されます。カスタムインストールも可能ですが、今回はデフォルトインストールを選択します。

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | 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/XXXXX/.rustup

〜 省略 〜

Current installation options:


   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    

〜 省略 〜

info: default toolchain set to 'stable-x86_64-apple-darwin'

  stable-x86_64-apple-darwin installed - rustc 1.55.0 (c8dfcfe04 2021-09-06)


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

これでインストールは完了です。ただしパスを設定していないため次にパスを設定します。

環境設定

ターミナルを開いた時にパスを通すように設定します。
私のMacの環境では、.zshrcを利用しているため、以下の内容を.zshrcに追加しています。

.zshrc
# Rust(20211002 add)
export PATH=${HOME}/.cargo/bin:${PATH}

また、sourceコマンドにより手動で環境変数を設定することもできます。

$ source $HOME/.cargo/env

バージョン確認

$ rustup --version
rustup 1.24.3 (ce5817a94 2021-05-31)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.55.0 (c8dfcfe04 2021-09-06)`

$ rustc --version
rustc 1.55.0 (c8dfcfe04 2021-09-06)

$ cargo --version
cargo 1.55.0 (32da73ab1 2021-08-23)

また、$ rustup showコマンドでツールキットの情報を表示することができます。

Rustアンインストール

Rustは、コマンドで簡単にアンインストールすることができます。

$ rustup self uninstall

さいごに

Rustのサイトに載っているインストールをごく普通にインストールをしただけ、かつIntel Macに導入しています。
M1 Macの場合、Rosetta2を通してRustを利用することになると思います。参考サイトに丁寧に解説してくださっているサイトを載せておきますので、M1 Macへインストールを考えている方は一度見ても良いと思います。

参考サイト

Rustプログラミング言語サイト
Oxidized Bookshelf

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0