How to Install Rust on Ubuntu & Debian

Rust is a systems programming language emphasizing memory safety and performance — increasingly used for web backends, CLI tools, and performance-critical services. This guide covers installation on a VPS.

Step 1 — Install Rust via rustup

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

rustup is the standard Rust installer and version manager — the official recommended installation method rather than distribution package managers, which often have older versions.

Step 2 — Load Rust into Your Current Shell

source "$HOME/.cargo/env"

Step 3 — Verify Installation

rustc --version
cargo --version

cargo is Rust's build tool and package manager, analogous to npm for Node.js or pip for Python.

Step 4 — Create a New Project

cargo new myapp
cd myapp

Step 5 — Build and Run

cargo run

Building an Optimized Release Binary

cargo build --release

Produces a significantly faster, optimized binary compared to the default debug build — always use --release for actual production deployment.

Managing Rust Versions

rustup update
rustup install 1.75.0
rustup default 1.75.0

Adding Dependencies

cargo add serde tokio

Adds a dependency to your Cargo.toml and fetches it — Rust's package ecosystem (crates.io) is well-integrated with cargo's tooling.

Deploying a Compiled Rust Binary

Unlike interpreted languages, a Rust application compiles to a single native binary — deployment is often as simple as copying the compiled binary to your server and running it, with no runtime dependency installation needed on the target server itself (assuming compatible architecture/OS).

Running as a systemd Service

sudo nano /etc/systemd/system/myapp.service
[Unit]
Description=My Rust Application

[Service]
ExecStart=/opt/myapp/target/release/myapp
Restart=always
User=appuser

[Install]
WantedBy=multi-user.target

Cross-Compiling (Building on One Architecture for Another)

rustup target add x86_64-unknown-linux-gnu
cargo build --release --target x86_64-unknown-linux-gnu

Useful if building on a different architecture (e.g. an ARM development machine) than your target deployment server, avoiding needing to compile directly on the production server.

Installing Build Dependencies (Sometimes Needed)

sudo apt install build-essential pkg-config libssl-dev -y

Some Rust crates (particularly those wrapping C libraries) need these system-level build tools present to compile successfully.

Common Errors

"linker `cc` not found" — install build-essential, which provides the necessary linker and compilation toolchain Rust depends on for the final linking step.

Continue Reading

Browse more articles in Programming Languages & Runtimes.

  • install rust ubuntu, rustup installation, cargo build release, rust vps setup
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Install PHP on Ubuntu & Debian (Complete Guide)

PHP powers a huge share of the web, including WordPress, Laravel, and Magento. This guide covers...

How to Install Node.js on Ubuntu & Debian (with NVM)

Node.js is a fast JavaScript runtime for building APIs, web applications, and backend services....

How to Install Python on Ubuntu & Debian

Python powers web frameworks like Django and Flask, automation scripts, and data applications....

How to Install Java (OpenJDK) on Ubuntu & Debian

Java powers enterprise applications, build tools like Maven and Gradle, and platforms like...

How to Install Composer for PHP Dependency Management

Composer is PHP's standard dependency manager, used by virtually every modern PHP framework...