How to Install Rust on Ubuntu 23.10
Rust is a multi-paradigm, general-purpose programming language that emphasizes performance, type safety, and concurrency. It enforces memory safety—ensuring that all references point to valid memory—without requiring the use of a garbage collector or reference counting present in other memory-safe languages.
Install Rust
Install the Rust using rustup
command line tool,
Run the below command to download the rustup
command,
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
Output:
root@vps:~# curl --proto '=https' --tlsv1.3 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.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
/root/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory is located at:
/root/.cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/root/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/root/.profile
/root/.bashrc
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: x86_64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
It will ask for installation type. Enter 1 to proceed further with installation.
>1
info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2023-10-05, rust version 1.73.0 (cc66ad468 2023-10-03)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
7.8 MiB / 7.8 MiB (100 %) 4.3 MiB/s in 1s ETA: 0s
info: installing component 'clippy'
info: installing component 'rust-docs'
13.8 MiB / 13.8 MiB (100 %) 1.3 MiB/s in 6s ETA: 0s
info: installing component 'rust-std'
24.7 MiB / 24.7 MiB (100 %) 5.5 MiB/s in 4s ETA: 0s
info: installing component 'rustc'
61.6 MiB / 61.6 MiB (100 %) 6.9 MiB/s in 8s ETA: 0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'
stable-x86_64-unknown-linux-gnu installed - rustc 1.73.0 (cc66ad468 2023-10-03)
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"
root@vps:~#
Run the below command to add the Rust toolchain directory to the PATH environment variable,
source "$HOME/.cargo/env"
Verify the Installation
Verify the Rust installation by requesting the version,
rustc --version
Output:
root@vps:~# rustc --version
rustc 1.73.0 (cc66ad468 2023-10-03)
root@vps:~#
Installing a Compiler
First, update the Apt package index using below command,
apt update
apt upgrade
Once the upgrades are complete, install the build-essential package using the below command,
apt install build-essential
Creating, Compiling, and Running a Test Program, Start by creating some directories to store the test script,
mkdir ~/rustprojects
cd ~/rustprojects
mkdir testdir
cd testdir
Create a file in testdir to store your Rust code,
nano test.rs
Note: You need to use the
.rs
extension for all your Rust programs.
Add the following code into test.rs and save the file,
fn main() {
println!("Congratulations! You have installed your Rust program and it works.");
}
Compile the code using the rustc command,
rustc test.rs
Run the resulting executable,
./test
Output:
root@vps:~/rustprojects/testdir# ./test
Congratulations! You have installed your Rust program and it works.
root@vps:~/rustprojects/testdir# ./test
Congratulations! You have installed your Rust program and it works.
root@vps:~/rustprojects/testdir#
Use the below command to update the rustup
,
rustup update
Output:
root@vps:~/rustprojects/testdir# rustup update
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: checking for self-update
stable-x86_64-unknown-linux-gnu unchanged - rustc 1.73.0 (cc66ad468 2023-10-03)
info: cleaning up downloads & tmp directories
root@vps:~/rustprojects/testdir#
Done, you’ve installed and tested out Rust on Ubuntu 23.10
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS