Installing gazebo_ros_pkgs (ROS 2)


The set of ROS 2 packages for interfacing with Gazebo are contained within a meta package named gazebo_ros_pkgs. See ROS 2 Overview for background information before continuing here.

The packages support ROS 2 Crystal and Gazebo 9, and can be installed from debian packages or from source.


You should understand the basic concepts of ROS 2 and have gone through some ROS 2 Tutorials.

Install ROS 2

To install ROS 2 Crystal, see the ROS 2 installation page. Either a source or a binary installation should work; be sure to install the Crystal distribution.

Tip: Don't forget to source your setup.bash script as instructed on the ROS installation page.

Install Gazebo

You can install Gazebo either from source or from pre-build packages. See Install Gazebo.

You should install Gazebo 9. If installing from source, be sure to build the gazebo9 branch.

Tip: You may need to source Gazebo's setup file if you're having difficulty finding plugins and other resources. For example: . /usr/share/gazebo/

Install gazebo_ros_pkgs

Follow either the instructions to install from debian packages, or the instructions to install from source.

Install from debian packages (on Ubuntu)

Assuming you already have some Crystal debian packages installed, install gazebo_ros_pkgs as follows:

sudo apt install ros-crystal-gazebo-ros-pkgs

Install from source (on Ubuntu)

Tip: These instructions require the use of the colcon build tool, which is the standard tool used in ROS 2.

  1. Create a directory for the colcon workspace:

    mkdir -p ~/ws/src
  2. Make sure git is installed on your Ubuntu machine:

    sudo apt install git
  3. Download the source code from the gazebo_ros_pkgs repository:

    cd ~/ws/src
    git clone -b ros2
  4. Install all dependencies:

    cd ~/ws
    rosdep install --from-paths src --ignore-src -r -y
  5. Then build:

    cd ~/ws
    colcon build
  6. If you've had any problems building, be sure to ask for help at

  7. Be sure to source this workspace's install setup for every new terminal you open:

    . ~/ws/install/setup.bash

    Tip: You can make this be automatically sourced for every new terminal by running this once: echo "source ~/ws/install/setup.bash" >> ~/.bashrc

Testing Gazebo and ROS 2 integration

Assuming your ROS 2 and Gazebo environments have been properly setup and built, you should now be able to load Gazebo worlds which contain ROS 2 plugins, and to insert models at runtime which have ROS 2 plugins in them.

Gazebo ROS packages provides several demo worlds for you to get a quick start with the plugins. The demo worlds can be found here, and are installed by default under /opt/ros/<distro>/share/gazebo_plugins/worlds/.

Each world file comes with instructions at the top with some example commands that you can run to test its functionality, be sure to check that out!

Let's try loading one of them now!

  1. Open a new terminal

  2. Source ROS 2 as instructed when you installed ROS 2.

  3. Make sure you have some core tools installed:

    sudo apt install ros-crystal-ros-core ros-crystal-geometry2
  4. If you installed gazebo_ros_pkgs from source, source the workspace:

    . ~/ws/install/setup.bash
  5. Load the differential drive world with Gazebo:

    gazebo --verbose /opt/ros/crystal/share/gazebo_plugins/worlds/
  6. The Gazebo GUI should appear with a simple vehicle:

  7. On a new terminal (this is the 2nd one), run the following command to take a look at the world file.

    gedit /opt/ros/crystal/share/gazebo_plugins/worlds/
  8. See how the block on the top has a few example commands? Let's open a 3rd terminal and, again, source ROS 2 and gazebo_ros_pkgs as described above.

  9. Then run one of the commands, for example:

    ros2 topic pub /demo/cmd_demo geometry_msgs/Twist '{linear: {x: 1.0}}' -1
  10. You'll see the vehicle moving forward:

  11. Try out the other commands listed on the file, and try mofidying their values to get a feeling of how things work. Also try out other demo worlds!