There are 3 ways to install a global standalone version of Rust in Linux.
The recommended way is to use rustup with customized environment variables.
Using a Package Management Tool¶
Some Linux distributions provide packages for Rust. Taking Debian/Ubuntu based Linux distributions as an example, you can install a global version of Rust using the command below.
:::bash
wajig install rust rust-src cargo rustfmt Notice that the Rust version installed by this way is relatively old. Taking Ubuntu 22.04 as example, the above comamnd installs Rust 1.58.1 while the latest stable Rust version is 1.61.0 as of May 2022.
Using Environment Variable + rustup¶
By default, rustup installs Rust locally. However, you can configure environment variables to install Rust globally.
:::bash
export RUSTUP_HOME=/usr/local/rustup
export CARGO_HOME=/usr/local/cargo
export PATH=/usr/local/cargo/bin:$PATH
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shManually Install Rust Globally¶
Download Rust.
:::bash curl -sSL https://static.rust-lang.org/dist/rust-1.61.0-x86_64-unknown-linux-gnu.tar.gz -o /tmp/rust.tar.gzUntar the downloaded file.
:::bash tar -zxvf /tmp/rust.tar.gzGo to the untarred directory
rust-1.61.0-x86_64-unknown-linux-gnuand install Rust and necessary components.:::bash ./install.sh --without=rust-demangler-preview,rls-preview,rust-analysis-x86_64-unknown-linux-gnuGo to the directory
/usr/local/lib/rustliband remove non-needed files. You only to keep the 3 directoriesetc,srcandx86_64-unknown-linux-gnu.:::bash rm -rf !(etc|src|x86_64-unknown-linux-gnu)Download Rust source code.
:::bash curl -sSL https://static.rust-lang.org/dist/rustc-1.61.0-src.tar.gz -o /tmp/rust.tar.gzUntar the downloaded source file into the directory
/usr/local/lib/rustlib/src/rust/.:::bash mkdir -p /usr/local/lib/rustlib/src/rust tar -zxvf /tmp/rust.tar.gz -C /usr/local/lib/rustlib/src/rust --strip-components=1