0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rust を始める|導入から Hello World まで

0
Last updated at Posted at 2026-01-09

はじめに

この記事では Rust の導入から Hello World の実行までを初心者が初心者向けにまとめます。

環境

version
WSL 2.2.4.0
Ubuntu 22.04.4 LTS

日本語の公式ドキュメント

1.rustupのインストール

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

2.リンカの導入

リンカは、コンパイルされた出力をひとつのファイルに合体させるためにRustが使用するプログラム

Ubuntuの場合は、

sudo apt update
sudo apt install build-essential

3.ドキュメントの手順に沿って Hello, World!を出力するプログラムを作成する。

1. プロジェクトのディレクトリを作成する
$ mkdir ~/projects
$ cd ~/projects
$ mkdir hello_world
$ cd hello_world
2. Rustプログラムを書いて走らせる

:white_check_mark: Rustのファイルの拡張子は 「.rs

2-1. 実行ファイルを作成

main.rs
fn main() {
    // 世界よ、こんにちは
    println!("Hello, world!");
}

2-2. Rust プログラムのコンパイル

rustc main.rs

"Command 'rustc' not found, but can be installed with" になった場合

2-3. プログラムの実行

./main

Hello, world! が出力されている画面 :arrow_down:
スクリーンショット 2025-09-14 013012_copy.png

Hello, world!が確かに出力されたら、おめでとうございます!正式にRustプログラムを書きました。 Rustプログラマになったのです!ようこそ!

:laughing::laughing::laughing::laughing::laughing:

補足:エラー対応

PATHに通ってないため rustc が見つからず、下記のメッセージが表示される。

rustc main.rs
Command 'rustc' not found, but can be installed with:
sudo snap install rustup  # version 1.28.2, or
sudo apt  install rustc   # version 1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.22.04
See 'snap info rustup' for additional versions.

Rust を公式推奨の rustup でインストールした場合は、実行ファイルが ~/.cargo/bin/ に入る。

echo $PATH

出力に ~/.cargo/bin が含まれていない場合は追加

echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
 source ~/.bashrc

バージョンを確認

rustc --version
cargo --version

バージョンが返ってくれば :ok:

参考サイト

さいごに

読んでいただきありがとうございます。

Rust 初心者が学習のため執筆しています。
誤っている箇所などあれば教えていただけるとありがたいです。

次回

Rust の記述ルールなどについて学習していきます。

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?