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
- How to Deploy a Rust Application on a VPS
- Which Programming Language and Runtime Should You Deploy On?
- Process Managers Compared: PM2 vs systemd vs Supervisor
Browse more articles in Programming Languages & Runtimes.