How to fix ROS2 error hardware_interfaceConfig.cmake on Ubuntu

Problem

When trying to build some ROS package using colcon build, you see an error message such as

CMake Error at CMakeLists.txt:20 (find_package):
  By not providing "Findhardware_interface.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "hardware_interface", but CMake did not find one.

  Could not find a package configuration file provided by
  "hardware_interface" with any of the following names:

    hardware_interfaceConfig.cmake
    hardware_interface-config.cmake

  Add the installation prefix of "hardware_interface" to CMAKE_PREFIX_PATH or
  set "hardware_interface_DIR" to a directory containing one of the above
  files.  If "hardware_interface" provides a separate development package or
  SDK, be sure it has been installed.

Solution

Install the ros-<distro>-hardware-interface package. For example, for ROS2 Jazzy, run

sudo apt install ros-jazzy-hardware-interface