For the complete documentation index, see llms.txt. This page is also available as Markdown.

21.5 Rust Development Environment

This section introduces how to configure a Rust development environment (via rustup or pkg) on FreeBSD, including toolchain installation and version settings.

Rust is designed with memory safety and thread safety as core goals, and concurrent programming is also one of its important features.

Installing Rust

Install Rust using pkg:

# pkg install rust

Or install using Ports:

# cd /usr/ports/lang/rust/
# make install clean

Tip

The latest development version is available in Port lang/rust-nightly.

Note

The Rust version number 1.95.0 in this section is the Ports version at the time of writing. Please adjust according to the latest Rust version available in FreeBSD Ports, which can be queried with pkg search rust.

After successful installation, check the software version.

Display the Rust compiler version information:

$ rustc --version
rustc 1.95.0 (59807616e 2026-04-14) (built from a source tarball)

Display the Cargo (Rust package manager and build tool) version information:

A Blessing for a Beautiful World

Create a new project using cargo:

Enter the newly created project:

Edit the text file ~/projects/greeting/src/main.rs, ensuring it contains the following code (usually included by default when creating a new project):

After saving, run:

Compile and run the current Rust project.

JetBrains Rust Development Environment

Install using pkg:

Or install using Ports:

JetBrains Rust development environment interface example

Appendix: Managing Rust via rustup

rustup-init is used to install and initialize rustup as a regular or non-root user.

rustup is the official Rust version management tool. It can install the Rust programming language from official channels and manage and switch between different Rust versions, eliminating the need to rely on Ports' lang/rust and lang/rust-nightly. Similar to version managers for other programming languages, rustup provides convenient access to and management of various Rust versions.

Installing rustup

Install using pkg:

Install using Ports:

Managing Rust

Initialize the rustup management tool:

The output is similar to the following:

Follow the prompts to write the environment variables to the corresponding configuration file for your shell. For example, for sh, add the following to ~/.shrc:

Warning

Note the leading dot (.) in the command, otherwise you will get a "permission denied" error.

Reload the shell configuration:

Install the latest Rust stable toolchain and set it as the system default compiler.

The output is as follows:

References

  • Rust Project. The Rust Programming Language[EB/OL]. [2026-04-17]. https://doc.rust-lang.org/book/. The official Rust programming guide, covering core concepts such as ownership and lifetimes.

Last updated