1. 概要
ふふ、通常は、「Windows」からはじめたりするのでしょうが、ここは違う。
とりあえずは、「FreeBSD」へ。
2022年7月25日時点で、最新である「FreeBSD 13.1 RELEASE」の環境へインストールします。
実は、「Rust」には、3つの主要なプログラムがあるらしく、それぞれ
・rustup Rust のツールチェーンを管理
・rustc Rust コンパイラ
・cargo パッケージマネジャー(ビルドツール)
ちゅうんですが。
実は、「FreeBSD」には、「rustc」「cargo」は、「ports/pkg」のリポジトリに存在しており、何が依存しているのかはわかりませんが、わたしの使用しているアプリケーション群をインストールした時点で、既にインストールされておりました。
じゃぁ、これでいいかと思ったのですが、どうも「rustup」というものも必要なようなのです。
となれば、仕方ない。
「【Rustと遊ぼう】FreeBSD で Rust をインストールする」を参考にして、インストールしてみようと思います。
2. ダウンロード
参考サイトのやり方では、ユーザ環境へインストールするようです。
今んとこ、よくわかっていないので、まずは、参考サイトのやり方を踏襲します。
ダウンロードには、「curl」が必要なので、あらかじめ、「pkg/ports」でインストールしておきます。
その上で
curl https://sh.rustup.rs -sSf | sh
info: downloading installer
warning: it looks like you have an existing installation of Rust at:
warning: /usr/local/bin
warning: rustup should not be installed alongside Rust. Please uninstall your existing Rust first.
warning: Otherwise you may have confusion unless you are careful with your PATH
warning: If you are sure that you want both rustup and your already installed Rust
warning: then please reply `y' or `yes' or set RUSTUP_INIT_SKIP_PATH_CHECK to yes
warning: or pass `-y' to ignore all ignorable checks.
error: cannot install while Rust is installed
Continue? (y/N)
ここは、y だな。
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:
/home/hogehoge/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory is located at:
/home/hogehoge/.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:
/home/hogehoge/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile file located at:
/home/hogehoge/.profile
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: x86_64-unknown-freebsd
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>
ここは、1 にしておきます。
info: profile set to 'default'
info: default host triple is x86_64-unknown-freebsd
info: syncing channel updates for 'stable-x86_64-unknown-freebsd'
info: latest update on 2022-07-19, rust version 1.62.1 (e092d0b6b 2022-07-16)
info: downloading component 'cargo'
2.3 MiB / 6.5 MiB ( 36 %) 0 B/s in 1s ETA: Unknown 6.5 MiB / 6.5 MiB (100 %) 2.3 MiB/s in 2s ETA: 0s
・・・ 略 ・・・
nfo: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-freebsd'
stable-x86_64-unknown-freebsd installed - rustc 1.62.1 (e092d0b6b 2022-07-16)
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"
最後の方で、「source」せろと書いてありますが、これは、「sh/bash」用ですな。
なので、これはログインスクリプトにそれぞれ書くべきです。
「csh/tcsh」であれば
vi ~/.cshrc
下記の行を加えます。
set path=($path $HOME/.cargo/bin)
「bash」であれば
vi ~/.profile
がインストール時に変更されるので、なにもしなくて良さそうです。
3. 確認
参考サイトにならって、バージョンを確認します。
$ rustc -V
rustc 1.62.0
$ cargo -V
cargo 1.62.0
$ rustup -V
rustup 1.25.1 (bb60b1e89 2022-07-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.62.1 (e092d0b6b 2022-07-16)`
わざわざ、インストールしたのに、「rustup」と「rustc」「cargo」のバージョンが違う中のはどういうことなんじゃろね。
どうもこれは、パスの通る順番のせいで、まだバージョンアップしていない「ports」の方の「rustc」「cargo」が起動しているようです。
4. 余談
参考サイトにせっかく書いてくれているので、やってみてないですが、アンインストールは、下記のコマンドで行うようです。
rustup self uninstall