Skip to content

Instantly share code, notes, and snippets.

@takurx
Last active October 6, 2022 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takurx/61827fa23093c15fed6e02633fd681d2 to your computer and use it in GitHub Desktop.
Save takurx/61827fa23093c15fed6e02633fd681d2 to your computer and use it in GitHub Desktop.
Install Rust language and Hello, Rust
# command
```
cargo run
```
# log
```
chiya@ujimatsu:~/Works/hello_rust/hello_rust$ cargo run
Compiling hello_rust v0.1.0 (/home/chiya/Works/hello_rust/hello_rust)
warning: unused variable: `n`
--> src/main.rs:2:9
|
2 | for n in 1..3 {
| ^ help: if this is intentional, prefix it with an underscore: `_n`
|
= note: `#[warn(unused_variables)]` on by default
warning: `hello_rust` (bin "hello_rust") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.29s
Running `target/debug/hello_rust`
Hello, world!
Hello, world!
chiya@ujimatsu:~/Works/hello_rust/hello_rust$ cargo run
Compiling hello_rust v0.1.0 (/home/chiya/Works/hello_rust/hello_rust)
warning: unused variable: `n`
--> src/main.rs:2:9
|
2 | for n in 1..5 {
| ^ help: if this is intentional, prefix it with an underscore: `_n`
|
= note: `#[warn(unused_variables)]` on by default
warning: `hello_rust` (bin "hello_rust") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.26s
Running `target/debug/hello_rust`
Hello, world!
Hello, world!
Hello, world!
Hello, world!
chiya@ujimatsu:~/Works/hello_rust/hello_rust$ cd ..
chiya@ujimatsu:~/Works/hello_rust$ mv hello_rust hello_rust_for_loop
chiya@ujimatsu:~/Works/hello_rust$ cd hello_rust_for_loop/
chiya@ujimatsu:~/Works/hello_rust/hello_rust_for_loop$ cargo run
warning: unused variable: `n`
--> src/main.rs:2:9
|
2 | for n in 1..5 {
| ^ help: if this is intentional, prefix it with an underscore: `_n`
|
= note: `#[warn(unused_variables)]` on by default
warning: `hello_rust` (bin "hello_rust") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/hello_rust`
Hello, world!
Hello, world!
Hello, world!
Hello, world!
chiya@ujimatsu:~/Works/hello_rust/hello_rust_for_loop$ cargo run
warning: unused variable: `n`
--> src/main.rs:2:9
|
2 | for n in 1..5 {
| ^ help: if this is intentional, prefix it with an underscore: `_n`
|
= note: `#[warn(unused_variables)]` on by default
warning: `hello_rust` (bin "hello_rust") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/hello_rust`
Hello, world!
Hello, world!
Hello, world!
Hello, world!
chiya@ujimatsu:~/Works/hello_rust/hello_rust_for_loop$ cargo run
warning: unused variable: `n`
--> src/main.rs:2:9
|
2 | for n in 1..5 {
| ^ help: if this is intentional, prefix it with an underscore: `_n`
|
= note: `#[warn(unused_variables)]` on by default
warning: `hello_rust` (bin "hello_rust") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/hello_rust`
Hello, world!
Hello, world!
Hello, world!
Hello, world!
chiya@ujimatsu:~/Works/hello_rust/hello_rust_for_loop$ cargo run
warning: unused variable: `n`
--> src/main.rs:2:9
|
2 | for n in 1..5 {
| ^ help: if this is intentional, prefix it with an underscore: `_n`
|
= note: `#[warn(unused_variables)]` on by default
warning: `hello_rust` (bin "hello_rust") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/hello_rust`
Hello, world!
Hello, world!
Hello, world!
Hello, world!
chiya@ujimatsu:~/Works/hello_rust/hello_rust_for_loop$ cd ..
chiya@ujimatsu:~/Works/hello_rust$ cd hello_rust
chiya@ujimatsu:~/Works/hello_rust/hello_rust$ ls
src
chiya@ujimatsu:~/Works/hello_rust/hello_rust$ cargo run
error: could not find `Cargo.toml` in `/home/chiya/Works/hello_rust/hello_rust` or any parent directory
chiya@ujimatsu:~/Works/hello_rust/hello_rust$ cd ..
chiya@ujimatsu:~/Works/hello_rust$ rm -rf ./hello_rust
chiya@ujimatsu:~/Works/hello_rust$ cd hello_rust_for_loop/
chiya@ujimatsu:~/Works/hello_rust/hello_rust_for_loop$ cargo run
Compiling hello_rust v0.1.0 (/home/chiya/Works/hello_rust/hello_rust_for_loop)
Finished dev [unoptimized + debuginfo] target(s) in 0.28s
Running `target/debug/hello_rust`
Hello, world! 1
Hello, world! 2
Hello, world! 3
Hello, world! 4
```

command

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
git clone git@github.com:takurx/hello_rust.git
hello_rust/
rustc test.rs -o test
./test

Reference

  1. https://www.rust-lang.org/ja/learn/get-started
  2. https://takuwz.hatenablog.com/entry/2020/05/24/004855

log

chiya@ujimatsu:~/Works$ 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:

  /home/chiya/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/chiya/.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/chiya/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /home/chiya/.profile
  /home/chiya/.bashrc

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-linux-gnu
     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-linux-gnu
warning: Updating existing toolchain, profile choice will be ignored
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2022-09-22, rust version 1.64.0 (a55dd71d5 2022-09-19)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: removing previous version of component 'cargo'
info: removing previous version of component 'clippy'
info: removing previous version of component 'rust-docs'
info: removing previous version of component 'rust-std'
info: removing previous version of component 'rustc'
info: removing previous version of component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 18.8 MiB /  18.8 MiB (100 %)   9.1 MiB/s in  2s ETA:  0s
info: installing component 'rust-std'
 27.4 MiB /  27.4 MiB (100 %)  11.3 MiB/s in  2s ETA:  0s
info: installing component 'rustc'
 54.2 MiB /  54.2 MiB (100 %)  11.9 MiB/s in  4s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu updated - rustc 1.64.0 (a55dd71d5 2022-09-19) (from rustc 1.58.1 (db9d1b20b 2022-01-20))


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"
chiya@ujimatsu:~/Works$ source "$HOME/.cargo/env"
chiya@ujimatsu:~/Works$ git clone git@github.com:takurx/hello_rust.git
Cloning into 'hello_rust'...
remote: Enumerating objects: 8, done.
remote: Total 8 (delta 0), reused 0 (delta 0), pack-reused 8
Receiving objects: 100% (8/8), 367.47 KiB | 720.00 KiB/s, done.
chiya@ujimatsu:~/Works$ cd hello_rust/
chiya@ujimatsu:~/Works/hello_rust$ ls
test.exe  test.pdb  test.py  test.rs
chiya@ujimatsu:~/Works/hello_rust$ rustc test.rs -o test
chiya@ujimatsu:~/Works/hello_rust$ ./test 
Hello World!

command

cargo new hello-rust
cd hello-rust/
cargo run

log

chiya@ujimatsu:~/Works/hello_rust$ cargo new hello-rust
     Created binary (application) `hello-rust` package
chiya@ujimatsu:~/Works/hello_rust$ cd hello-rust/
chiya@ujimatsu:~/Works/hello_rust/hello-rust$ cargo run
   Compiling hello-rust v0.1.0 (/home/chiya/Works/hello_rust/hello-rust)
    Finished dev [unoptimized + debuginfo] target(s) in 0.49s
     Running `target/debug/hello-rust`
Hello, world!

command

cargo build
cargo run

log

hiya@ujimatsu:~/Works/hello_rust/hello-rust$ cargo build
    Updating crates.io index
  Downloaded textwrap v0.13.4
  Downloaded unicode-width v0.1.10
  Downloaded smawk v0.3.1
  Downloaded smallvec v0.4.5
  Downloaded ferris-says v0.2.1
  Downloaded 5 crates (99.9 KB) in 1.13s
   Compiling unicode-width v0.1.10
   Compiling smawk v0.3.1
   Compiling smallvec v0.4.5
   Compiling textwrap v0.13.4
   Compiling ferris-says v0.2.1
   Compiling hello-rust v0.1.0 (/home/chiya/Works/hello_rust/hello-rust)
    Finished dev [unoptimized + debuginfo] target(s) in 55.76s
chiya@ujimatsu:~/Works/hello_rust/hello-rust$ cargo run
   Compiling hello-rust v0.1.0 (/home/chiya/Works/hello_rust/hello-rust)
    Finished dev [unoptimized + debuginfo] target(s) in 0.61s
     Running `target/debug/hello-rust`
 __________________________
< Hello fellow Rustaceans! >
 --------------------------
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment