How to Display the Path to a ROS 2 Package

search-autumn-leaves

Let’s suppose you want to display the full path to a ROS 2 package so that you know which directory on your computer the package is located in. Let’s suppose you are using ROS 2 Galactic (you will replace ‘galactic’ with whatever ROS 2 distribution you are using).

For example, suppose you want to know where the rviz2 package is located.

Here is what you do…

Open a terminal window, and type:

ros2 pkg prefix rviz2

Here is what the output would look like in a terminal window:

ros2pkgprefix

Then to get to the folder, type:

cd /opt/ros/galactic/share/rviz2