How To Install Rust in Linux

Created
Modified

Running the following in your terminal

If you’re running macOS, Linux, or another Unix-like OS. To download Rustup and install Rust, run the following in your terminal, then follow the on-screen instructions.

curl
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
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

To configure your current shell, run:

Rust
source ~/.profile
source ~/.cargo/env
rustc --version
cargo --version
rustc 1.60.0 (7737e0b5c 2022-04-04)
cargo 1.60.0 (d1fd9fe 2022-03-01)

When you install Rustup you’ll also get the latest stable version of the Rust build tool and package manager, also known as Cargo.

On Windows, download and run rustup-init.exe.

Standalone installers

The official Rust standalone installers contain a single release of Rust, and are suitable for offline installation. See: https://forge.rust-lang.org/infra/other-installation-methods.html

Try Rust Online

You can try Rust online in the Rust Playground without installing anything on your computer. See: TRY RUST WITHOUT INSTALLING

Rustc Help Commands and Options

Usage: rustc [OPTIONS] INPUT

OPTIONS:
-h, --help
Display this message
--cfg SPEC
Configure the compilation environment
-L [KIND=]PATH
Add a directory to the library search path. The optional KIND can be one of dependency, crate, native, framework, or all (the default).
-l [KIND[:MODIFIERS]=]NAME[:RENAME]
Link the generated crate(s) to the specified native library NAME. The optional KIND can be one of static, framework, or dylib (the default). Optional comma separated MODIFIERS (bundle|verbatim|whole-archive|as-needed) may be specified each with a prefix of either '+' to enable or '-' to disable.
--crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]
Comma separated list of types of crates for the compiler to emit
--crate-name NAME
Specify the name of the crate being built
--edition 2015|2018|2021
Specify which edition of the compiler to use when compiling code.
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
Comma separated list of types of output for the compiler to emit
--print [crate-name|file-names|sysroot|target-libdir|cfg|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|native-static-libs|stack-protector-strategies|link-args]
Compiler information to print on stdout
-g
Equivalent to -C debuginfo=2
-O
Equivalent to -C opt-level=2
-o FILENAME
Write output to filename
--out-dir DIR
Write output to compiler-chosen filename in dir
--explain OPT
Provide a detailed explanation of an error message
--test
Build a test harness
--target TARGET Target triple for which the code is compiled
-A, --allow LINT
Set lint allowed
-W, --warn LINT
Set lint warnings
--force-warn LINT
Set lint force-warn
-D, --deny LINT
Set lint denied
-F, --forbid LINT
Set lint forbidden
--cap-lints LEVEL
Set the most restrictive lint level. More restrictive
lints are capped at this level
-C, --codegen OPT[=VALUE]
Set a codegen option
-V, --version
Print version info and exit
-v, --verbose
Use verbose output

Cargo Help Commands and Options

Rust's package manager

USAGE:
    cargo [+toolchain] [OPTIONS] [SUBCOMMAND]

OPTIONS:
-V, --version
Print version info and exit
--list
List installed commands
--explain <CODE>
Run `rustc --explain CODE`
-v, --verbose
Use verbose output (-vv very verbose/build.rs output)
-q, --quiet
Do not print cargo log messages
--color <WHEN>
Coloring: auto, always, never
--frozen
Require Cargo.lock and cache are up to date
--locked
Require Cargo.lock is up to date
--offline
Run without accessing the network
--config <KEY=VALUE>
Override a configuration value (unstable)
-Z <FLAG>
Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
-h, --help
Print help information
Commands: Some common cargo commands are (see all commands with --list):
build, b
Compile the current package
check, c
Analyze the current package and report errors, but don't build object files
clean
Remove the target directory
doc, d
Build this package's and its dependencies' documentation
new
Create a new cargo package
init
Create a new cargo package in an existing directory
run, r
Run a binary or example of the local package
test, t
Run the tests
bench
Run the benchmarks
update
Update dependencies listed in Cargo.lock
search
Search registry for crates
publis
Package and upload this package to the registry
install
Install a Rust binary. Default location is $HOME/.cargo/bin
uninstall
Uninstall a Rust binary
See 'cargo help <command>' for more information on a specific command.

Related Tags