40.5 Rust 开发环境
最后更新于
$ cargo --version
cargo 1.95.0 (f2d3ce0bd 2026-03-21) (built from a source tarball)$ cargo new ~/projects/greeting
Creating binary (application) `greeting` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html$ cd $_fn main() { // Rust 程序入口函数
println!("Hello, world!"); // 输出“Hello, world!”到控制台
}$ cargo run
Compiling greeting v0.1.0 (/home/ykla/projects/greeting)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.37s
Running `target/debug/greeting`
Hello, world!# pkg install jetbrains-rustrover# cd /usr/ports/devel/jetbrains-rustrover/
# make install clean# pkg install rustup-init# cd /usr/ports/devel/rustup-init/
# make install clean$ rustup-init --profile minimal --default-toolchain none -yinfo: profile set to 'minimal'
info: default host triple is x86_64-unknown-freebsd
info: skipping toolchain installation
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, you need to source
the corresponding env file under $HOME/.cargo.
This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env" # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish" # For fish
source "$HOME/.cargo/env.nu" # For nushell. $HOME/.cargo/env$ . ~/.shrc$ rustup default stableinfo: syncing channel updates for 'stable-x86_64-unknown-freebsd'
info: latest update on 2026-04-16, rust version 1.95.0 (59807616e 2026-04-14)
info: downloading component 'cargo'
11.1 MiB / 11.1 MiB (100 %) 5.4 MiB/s in 3s
info: downloading component 'rust-std'
27.5 MiB / 27.5 MiB (100 %) 7.6 MiB/s in 3s
info: downloading component 'rustc'
88.4 MiB / 88.4 MiB (100 %) 15.1 MiB/s in 32s
info: installing component 'cargo'
info: installing component 'rust-std'
27.5 MiB / 27.5 MiB (100 %) 11.7 MiB/s in 2s
info: installing component 'rustc'
88.4 MiB / 88.4 MiB (100 %) 13.4 MiB/s in 37s
info: default toolchain set to 'stable-x86_64-unknown-freebsd'
stable-x86_64-unknown-freebsd installed - rustc 1.95.0 (59807616e 2026-04-14)