Setting Up a Rust Project on Ubuntu and Debugging in VSCode on Windows

You have set up a Rust environment on a Ubuntu server and installed Visual Studio Code (VSCode) on your local Windows machine, connecting to the Ubuntu server via the Remote-SSH extension. This guide will walk you through creating a Rust project on Ubuntu and developing and debugging it using VSCode.

Step 1: Create a Rust Project on Ubuntu

  1. Connect to the Ubuntu server using the Remote-SSH extension in VSCode.
  2. Open a terminal in VSCode (use Ctrl + ~ or go to Terminal > New Terminal).
  3. Verify that the Rust toolchain is installed and configured:
rustc --version
cargo --version

This should display the versions of the Rust compiler (rustc) and the build tool (cargo).

  1. Create a new Rust project using Cargo:
cargo new my_rust_app --bin

Here, my_rust_app is the name of the project, and --bin specifies that it's an executable Rust project. For a library, use cargo new my_rust_app --lib.

  1. Navigate into the project directory:
cd my_rust_app

Step 2: Open the Rust Project in VSCode

  1. In the Remote-SSH session of VSCode, click File > Open Folder, and select the project folder my_rust_app.
  2. VSCode will open the project structure, showing files like Cargo.toml and src/main.rs.

Step 3: Install Rust Extension (Rust Analyzer)

  1. In the VSCode extension marketplace, search for and install the Rust Analyzer extension. This extension provides features like smart completion, syntax checking, and more for Rust development.
  2. After installation, Rust Enalyzer will automatically activate and analyze your Rust project.

Step 4: Write and Run Rust Code

  1. Open the src/main.rs file and modify the initial code to write a simple Rust program, e.g.:
fn main() {
    println!("Welcome to Rust programming!");
}
  1. In the VSCode terminal, execute the following command to build and run the project:
cargo run

You should see the output:

Welcome to Rust programming!

Step 5: Configure VSCode for Debugging

To debug Rust programs in VSCode, you need to install a debugger and configure the debugging environment.

  1. Install CodeLLDB Extension
  2. In the VSCode extension marketplace, search for and install the CodeLLDB extension. This extension is the LLDB debugger for Rust.
  3. Create Debug Configuration
  4. Press F5 or click Run > Add Configuration. If prompted, choose Rust (CodeLLDB).
  5. This will create a .vscode/launch.json file in your project directory with a default configuration similar to:
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug",
            "program": "${workspaceFolder}/target/debug/my_rust_app",
            "args": [],
            "cwd": "${workspaceFolder}",
            "stopOnEntry": false,
            "preLaunchTask": "cargo build",
            "sourceLanguages": ["rust"]
        }
    ]
}
  1. Start Debugging
  2. The program field in launch.json specifies the path to the executable file generated by the Rust project (target/debug/my_rust_app).
  3. Press F5 to start debugging. VSCode will compile the project and launch it in the LLDB debugger.

Step 6: Set Breakpoints and Debug

  1. Open the src/main.rs file and set breakpoints by clicking on the left margin next to the line numbers where you want to pause execution.
  2. Press F5 to start debugging. The program will run and pause at breakpoints.
  3. While paused, you can use these features:
    • Inspect Variables: The debug window shows variables and their values in the current scope.
    • Step Through Code: Use toolbar buttons Step Over (F10), Step Into (F11), and Step Out (Shift+F11) to navigate through the code.
    • View Call Stack: The debug window displays the call stack, aiding in analyzing the program's execution path.

Tags: rust VSCode remote-ssh Ubuntu cargo

Posted on Fri, 17 Jul 2026 16:54:39 +0000 by kishan