Ubuntu Linux for Robotics · Lesson 22 of 96
Using VS Code on Linux
Installing, extensions for C++, Python and ROS, remote SSH, tasks and debugging.
Estimated time · 45–60 min
Learning goals
What you will understand
- Explain using vs code on linux in your own words
- Use it in a small workstation example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
Visual Studio Code is the usual editor for ROS 2 development. Install it from Microsoft's apt repository or the .deb package, then add extensions: C/C++, CMake Tools, Python, ROS and Remote - SSH. Open a workspace with code ~/robot_ws so the editor sees the whole project.
Remote - SSH lets you edit files on the robot as if they were local, while the code and compilers run on the robot. Use compile_commands.json (cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON) for accurate IntelliSense, tasks.json for colcon build and launch.json for gdb debugging.
Guided lesson
Work through these steps
- 1.
Open a terminal and record the current state before changing anything.
- 2.
Read the using vs code on linux commands and predict what each one does.
- 3.
Run the commands one at a time and compare each output with your prediction.
- 4.
Write the commands that worked in a setup note you can repeat later.
Worked example
Read it before you run it
sudo apt install ./code_amd64.deb
# Install the .deb downloaded from the VS Code website (also sets up updates).
code ~/robot_ws
# Open the workspace folder in VS Code.
code --install-extension ms-vscode.cpptools
# Install C/C++ support from the terminal.
code --install-extension ms-python.python
# Install Python support.
code --install-extension ms-vscode-remote.remote-ssh
# Install remote editing over SSH.
colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
# Produce the file IntelliSense uses to find headers.What the example is doing
- 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
- 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
- 3.Comments beginning with # explain safety checks and are not executed by the shell.
Watch it run · Build and run
See what this code does
The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.
Demo for Using VS Code on Linux. Expected result: VS Code opens ~/robot_ws with the C/C++ extension enabled
Practice code
Now type it yourself
Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.
# TODO: install the C/C++ extension ms-vscode.cpptools and open ~/robot_wsExpected output
VS Code opens ~/robot_ws with the C/C++ extension enabledStuck? Show the full solution (try it yourself first)
code --install-extension ms-vscode.cpptools
code ~/robot_wsExpected result
How you know it worked
- Each command completes without an unexplained error.
- Your notes contain the command, the important output, and what it proves.
Practical exercise
Apply the lesson
Install VS Code and the extensions, connect to a robot or virtual machine with Remote - SSH, open a ROS 2 package, create a build task for colcon, and set a breakpoint in a C++ node.
Before you continue
- You recorded the starting state
- Every command and output is understood
- The change can be repeated from your notes
If something goes wrong
Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.
Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.