Rust setup on Ubuntu VSCode

Setting up Rust with VSCode on Ubuntu involves several steps. Here’s a detailed guide to get you started:

1. Install Rust

  1. Install Rust using rustup: Open your terminal and run:

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

    This command will download and run the Rust installation script. Follow the on-screen instructions.

  2. Configure your shell: After installation, you may need to configure your shell to use Rust. Run:

    source $HOME/.cargo/env
  3. Verify the installation: Check if Rust is installed correctly by running:

    rustc --version

2. Install Visual Studio Code

  1. Install VSCode: If you don’t have VSCode installed, you can install it using the following commands:

    sudo apt update
    sudo apt install software-properties-common apt-transport-https wget
    wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
    sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
    sudo apt update
    sudo apt install code

3. Set Up Rust in VSCode

  1. Open VSCode: Launch VSCode from your application menu or by typing code in your terminal.

  2. Install the Rust Extension:

    • Go to the Extensions view by clicking on the Extensions icon in the sidebar or pressing Ctrl+Shift+X.

    • Search for "rust-analyzer" and click "Install". This is a popular Rust language server extension that provides features like code completion, navigation, and more.

  3. Install rustfmt and clippy: These tools help with code formatting and linting.

  4. Configure VSCode for Rust:

    • Open a Rust project or create a new one using cargo new project_name.

    • Open the project folder in VSCode.

    • The rust-analyzer extension should automatically detect your Rust setup. You may need to restart VSCode or reload the window (Ctrl+Shift+P and select "Reload Window").

4. Additional Tools

  • Debugger: For debugging Rust code, you can install the CodeLLDB extension:

    • Go to the Extensions view.

    • Search for "CodeLLDB" and install it.

  • Create and Run a Simple Rust Program:

    • Create a new Rust project:

    • Open the project in VSCode.

    • In the terminal, run:

That’s it! You now have Rust set up with VSCode on Ubuntu. If you run into any issues or have specific questions, feel free to ask!

Last updated