How to Install and Configure Visual Studio Code for ROS 2

3-visual-studio-code

In this tutorial, we will go over how to install and configure Visual Studio Code for your ROS 2 projects.

Visual Studio Code, often shortened to VS Code, is a free and open-source code editor developed by Microsoft. It’s a popular choice for programmers of all levels, from beginners to professionals, because it’s:

  • Lightweight and fast: It doesn’t take up much space on your computer and starts up quickly, so you can get coding right away.
  • Versatile: It supports a wide range of programming languages, including JavaScript, Python, Java, C++, and more. You can also install extensions to add support for even more languages.
  • Customizable: You can personalize VS Code with themes, extensions, and keyboard shortcuts to make it work the way you want.
  • Feature-rich: It comes with built-in features like syntax highlighting, code completion, and debugging, which can help you write better code faster.

Let’s get started!

Prerequisites

Directions

Go to this page.

Click the .deb button.

Open a terminal window, and type:

cd ~/Downloads

Run the following command, replacing “filename.deb” with the actual name of your file:

sudo dpkg -i filename.deb

Enter your password when prompted.

The installation will start. Wait for it to complete.

Open VS Code by typing this command in a terminal window:

code
4-open-vs-code

Double-click on the Extensions button on the bottom left side of the window.

5-extensions-tab

Search for the “C/C++” extension.

6-cpp-extension

Install it.

Search for the “ROS” extension.

7-ros-extension-microsoft

Install the ROS extension from Microsoft by clicking the Install button. 

We haven’t created a ROS 2 workspace, but when we do, we will open VS Code as follows:

cd ~/ros2_ws/src
code .

Now let’s install the CMake extension. Search for “CMake”, and install the version made by twxs.

Install the CMake Tools extensions. Search for “CMake Tools”, and install the version made by Microsoft.

Install the XML extensions. Search for “XML”, and install the version made by Red Hat.

Now let’s install the Python extension. Search for “python”, and install the version made by Microsoft. Note: You may have already installed it. 

Install the autoDocstring extension. Search for “autoDocstring”, and install the version made by Nils Werner.

That’s it! 

Now you can close VS Code by going to File -> Exit.