ものづくりのブログ

うちのネコを題材にしたものづくりができたらいいなと思っていろいろ奮闘してます。

【Rust】Ubuntu 環境にインストール

Ubuntu 環境に Rust をインストールした時のメモをここに残します。

環境

セットアップ

インストール

$ curl https://sh.rustup.rs -sSf | sh

パスの設定

$ source $HOME/.cargo/env

バージョン確認

$ cargo --version
cargo 1.66.0 (d65d197ad 2022-11-15)
$ rustc --version
rustc 1.66.0 (69f9c33d7 2022-12-12)
$ rustdoc --version
rustdoc 1.66.0 (69f9c33d7 2022-12-12)
$ rustup --version
rustup 1.25.1 (bb60b1e89 2022-07-12)

コマンド

rustc		// Rustコンパイラ
rustup		// Rustインストーラ・アップデータ
cargo		// Rustパッケージマネージャ
rustdoc		// ドキュメント生成ツール(rustdoc)
rustfmt		// コーディングスタイル整形ツール

サンプル

コード

hello.rs というファイルを作成します。

fn main() {
  println!("Hello world");
}

rustc でコンパイル

$ rustc hello.rs -o hello
$ ./hello 
Hello world

cargoでコンパイル

$ cargo new sample
     Created binary (application) `sample` package
$ cd hello
$ cargo build
   Compiling sample v0.1.0 (/data/xxxx/sample)
    Finished dev [unoptimized + debuginfo] target(s) in 0.49s
$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/sample`
Hello world