This code works on Ros2 Humble. Check other branches of this repository to download the code for other ROS versions.
$ sudo apt-get install ros-humble-nav2-map-server libompl-dev ros-humble-moveit-planners-ompl
$ cd ~/ros2_ws/src
$ git clone https://github.com/dominikbelter/ompl_example_2d
$ cd ~/ros2_ws/
$ colcon build --symlink-install
$ . install/setup.bash
$ ros2 launch ompl_example_2d ompl_example_2d.launch.py