06152020 Install Rust


It has been installed on my Mac. I show the process below.

porry@Porry15MBP:~/Documents/WorkGroups/Rust$ curl https://sh.rustup.rs -sSf | 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.


It will add the cargo, rustc, rustup and other commands to

Cargo's bin directory, located at:


  /Users/porry/.cargo/bin


This can be modified with the CARGO_HOME environment variable.


Rustup metadata and toolchains will be installed into the Rustup

home directory, located at:


  /Users/porry/.rustup


This can be modified with the RUSTUP_HOME environment variable.


This path will then be added to your PATH environment variable by

modifying the profile files located at:


  /Users/porry/.profile

/Users/porry/.bash_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-apple-darwin

     default toolchain: stable

               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-apple-darwin

info: syncing channel updates for 'stable-x86_64-apple-darwin'

info: latest update on 2020-06-04, rust version 1.44.0 (49cae5576 2020-06-01)

info: downloading component 'cargo'

  3.9 MiB /   3.9 MiB (100 %)   1.2 MiB/s in  3s ETA:  0s

info: downloading component 'clippy'

info: downloading component 'rust-docs'

 12.2 MiB /  12.2 MiB (100 %)   1.4 MiB/s in  8s ETA:  0s

info: downloading component 'rust-std'

 16.5 MiB /  16.5 MiB (100 %)   1.7 MiB/s in 10s ETA:  0s

info: downloading component 'rustc'

 55.9 MiB /  55.9 MiB (100 %)   1.2 MiB/s in 46s ETA:  0s

info: downloading component 'rustfmt'

  2.1 MiB /   2.1 MiB (100 %)   1.4 MiB/s in  1s ETA:  0s

info: installing component 'cargo'

info: installing component 'clippy'

info: installing component 'rust-docs'

 12.2 MiB /  12.2 MiB (100 %)   4.4 MiB/s in  2s ETA:  0s

info: installing component 'rust-std'

info: installing component 'rustc'

 55.9 MiB /  55.9 MiB (100 %)  12.9 MiB/s in  4s ETA:  0s

info: installing component 'rustfmt'

info: default toolchain set to 'stable'


  stable installed - rustc 1.44.0 (49cae5576 2020-06-01)



Rust is installed now. Great!


To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH

environment variable. Next time you log in this will be done

automatically.


To configure your current shell run source $HOME/.cargo/env


Now, I don't want to restart my computer, so I configure my current shell to run the command.

porry@Porry15MBP:~/Documents/WorkGroups/Rust$ source $HOME/.cargo/env 


Let me check its version.

porry@Porry15MBP:~/Documents/WorkGroups/Rust$ rustc --version

rustc 1.44.0 (49cae5576 2020-06-01)


Finally, I try to display a hello world example to complete the installation steps.

porry@Porry15MBP:~/Documents/WorkGroups/Rust$ mkdir hello

porry@Porry15MBP:~/Documents/WorkGroups/Rust$ cd hello/

porry@Porry15MBP:~/Documents/WorkGroups/Rust/hello$ vim hello.rs

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

porry@Porry15MBP:~/Documents/WorkGroups/Rust/hello$ rustc hello.rs 

porry@Porry15MBP:~/Documents/WorkGroups/Rust/hello$ ./hello 

Hello, world!


==========================================================================

How to use cargo to build and run a hello world?

1. make sure cargo already installed

porry@Porry15MBP:~/Documents/WorkGroups/Rust/hello$ cargo --version

cargo 1.44.0 (05d080faa 2020-05-06)


2. create a new cargo sample

porry@Porry15MBP:~/Documents/WorkGroups/Rust/hello$ cargo new hello_cargo

     Created binary (application) `hello_cargo` package

porry@Porry15MBP:~/Documents/WorkGroups/Rust/hello$ cd hello_cargo/

porry@Porry15MBP:~/Documents/WorkGroups/Rust/hello/hello_cargo$ ls

Cargo.toml  src/


3. use "cargo build" or "cargo check"

porry@Porry15MBP:~/Documents/WorkGroups/Rust/hello/hello_cargo$ cargo build

   Compiling hello_cargo v0.1.0 (/Users/porry/Documents/WorkGroups/Rust/hello/hello_cargo)

    Finished dev [unoptimized + debuginfo] target(s) in 4.28s

porry@Porry15MBP:~/Documents/WorkGroups/Rust/hello/hello_cargo$ ls

Cargo.lock  Cargo.toml  src/        target/


4. run

porry@Porry15MBP:~/Documents/WorkGroups/Rust/hello/hello_cargo$ cargo run

    Finished dev [unoptimized + debuginfo] target(s) in 0.00s

     Running `target/debug/hello_cargo`

Hello, world!



Comments

  1. How to get to Harrah's Resort Atlantic City via SkyCity - Dr
    Directions to Harrah's 거제 출장안마 Resort Atlantic City via SkyCity (ACY) 사천 출장마사지 and 청주 출장안마 804-751-3000. The 오산 출장마사지 following transit lines 충청북도 출장샵 have routes that pass near Harrah's

    ReplyDelete

Post a Comment