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
Install Rust using rustup: Open your terminal and run:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shThis command will download and run the Rust installation script. Follow the on-screen instructions.
Configure your shell: After installation, you may need to configure your shell to use Rust. Run:
source $HOME/.cargo/envVerify the installation: Check if Rust is installed correctly by running:
rustc --version
2. Install Visual Studio Code
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
Open VSCode: Launch VSCode from your application menu or by typing
codein your terminal.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.
Install
rustfmtandclippy: These tools help with code formatting and linting.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-analyzerextension should automatically detect your Rust setup. You may need to restart VSCode or reload the window (Ctrl+Shift+Pand select "Reload Window").
4. Additional Tools
Debugger: For debugging Rust code, you can install the
CodeLLDBextension: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