How to Completely Uninstall ROS2 from Ubuntu

This tutorial provides a step-by-step guide to completely uninstalling ROS2 from an Ubuntu system. It is intended for systems where ROS2 was installed via apt using the official binary installation method. Whether the goal is to switch to a different ROS2 distribution, reinstall from source, or simply remove ROS2 to clean up the development environment, following these instructions will ensure that all ROS2-related packages, environment configurations, and repository sources are properly removed. By completing this process, the system will be free of any ROS2 components, providing a clean and conflict-free environment for future installations or other software setups.

 

✅​ Check Installed ROS2 Distributions

First, check which ROS or ROS2 distributions you currently have installed. Open a terminal and navigate to:

				
					cd /opt/ros
ls

				
			

This will list the installed distributions. Note which ones you want to remove.

❌ Remove ROS2 Packages

To remove all installed ROS2 packages, run:

				
					sudo apt remove ros-*


				
			

If you want to remove a specific distribution, use:

				
					sudo apt remove ros-[distribution]-*

				
			

After that, clean up unnecessary dependencies:

				
					sudo apt autoremove

				
			

Then, check if the distribution folder is still in /opt:

				
					ls /opt

				
			

If any ROS2-related directories remain, delete them manually:

				
					sudo rm -rf /opt/ros/[distribution]

				
			

🧹 Clean Up the Environment

When you installed ROS2 and set up workspaces, you probably added lines to your .bashrc file to source the environment each time a new terminal opens.

Open the file:

				
					gedit ~/.bashrc

				
			

Remove any lines containing references to ROS2 installations or workspaces, such as:

				
					source /opt/ros/
source ~/ros2_ws/

				
			

Save and close the file.

 

If you’ve created ROS2 workspaces and no longer need them, you can delete those too. It’s a good idea to back them up (e.g., via Git) before removal. Additionally, if you installed any ROS-related extensions in VS Code or other editors, you might want to uninstall those as well.

 ❌ Remove ROS2 Repositories

When ROS2 was installed, it added a new apt source. To check if it’s still active:

				
					sudo apt update

				
			

If you see a line containing packages.ros.org/ros2/ubuntu, remove the corresponding source file:

				
					cd /etc/apt/sources.list.d/
sudo rm ros2.list

				
			

Then, update apt again:

				
					sudo apt update

				
			

Finally, run one last clean-up and reboot:

				
					sudo apt autoremove
sudo reboot

				
			

 

At this point, ROS2 should be fully removed from the system. All related packages, environment configurations, and repository sources have been cleaned up, leaving the system free of any ROS2 components. The machine is now ready for a fresh ROS2 installation, a different distribution setup, or for use without ROS2, depending on the intended workflow. Performing a system reboot after the removal process is recommended to ensure that all changes are fully applied and no residual environment variables or processes remain active.

Want to learn more?

You can find a detailed explaination of the workspace in the "Self Driving and ROS 2 - Learn by Doing! Odometry & Control" course
DISCOUNT
es_ES